diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index 7b743aaab49f..9306a6ac50fe 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -492,7 +492,12 @@ object Implicits: /** An ambiguous implicits failure */ class AmbiguousImplicits(val alt1: SearchSuccess, val alt2: SearchSuccess, val expectedType: Type, val argument: Tree) extends SearchFailureType { def explanation(using Context): String = - em"both ${err.refStr(alt1.ref)} and ${err.refStr(alt2.ref)} $qualify" + var str1 = err.refStr(alt1.ref) + var str2 = err.refStr(alt2.ref) + if str1 == str2 then + str1 = ctx.printer.toTextRef(alt1.ref).show + str2 = ctx.printer.toTextRef(alt2.ref).show + em"both $str1 and $str2 $qualify" override def whyNoConversion(using Context): String = if !argument.isEmpty && argument.tpe.widen.isRef(defn.NothingClass) then "" diff --git a/tests/neg/i12591.check b/tests/neg/i12591.check new file mode 100644 index 000000000000..694eb68e3299 --- /dev/null +++ b/tests/neg/i12591.check @@ -0,0 +1,4 @@ +-- Error: tests/neg/i12591/Inner.scala:12:31 --------------------------------------------------------------------------- +12 |val badSummon = summon[TC[Bar]] // error here + | ^ + |ambiguous implicit arguments: both outer.inner.Foo.ofFoo and outer.Foo.ofFoo match type outer.inner.Foo.TC[outer.Bar] of parameter x of method summon in object Predef diff --git a/tests/neg/i12591/Inner.scala b/tests/neg/i12591/Inner.scala new file mode 100644 index 000000000000..aae9bd5b9234 --- /dev/null +++ b/tests/neg/i12591/Inner.scala @@ -0,0 +1,13 @@ +package outer +package inner + +sealed trait Foo +object Foo: + trait TC[T] + given ofFoo[T <: Foo]: TC[T] = ??? + trait Bar extends Foo + +import Foo.TC +//Adding import Foo.Bar resolves the issue +val badSummon = summon[TC[Bar]] // error here + diff --git a/tests/neg/i12591/Outer.scala b/tests/neg/i12591/Outer.scala new file mode 100644 index 000000000000..5c810ec785fe --- /dev/null +++ b/tests/neg/i12591/Outer.scala @@ -0,0 +1,3 @@ +package outer +export inner.Foo +export Foo.Bar