Skip to content

Improve display of references for ambiguous implicit errors #12614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
""
Expand Down
4 changes: 4 additions & 0 deletions tests/neg/i12591.check
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/neg/i12591/Inner.scala
Original file line number Diff line number Diff line change
@@ -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

3 changes: 3 additions & 0 deletions tests/neg/i12591/Outer.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package outer
export inner.Foo
export Foo.Bar