Skip to content

Commit e919d98

Browse files
committed
Give full info for nested ambiguities
1 parent a0439b9 commit e919d98

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
351351
case id: Trees.SearchFailureIdent[?] =>
352352
tree.typeOpt match {
353353
case reason: Implicits.SearchFailureType =>
354-
toText(id.name) ~ "summon[" ~ toText(reason.clarify(reason.expectedType)) ~ "]"
354+
toText(id.name)
355+
~ ("summon[" ~ toText(reason.clarify(reason.expectedType)) ~ "]").close
355356
case _ =>
356357
toText(id.name)
357358
}

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,10 @@ object Implicits {
379379
}
380380

381381
object SearchFailure {
382-
def apply(tpe: SearchFailureType)(implicit src: SourceFile): SearchFailure = {
383-
val id =
384-
if (tpe.isInstanceOf[AmbiguousImplicits]) "/* ambiguous */"
385-
else "/* missing */"
382+
def apply(tpe: SearchFailureType)(using Context): SearchFailure = {
383+
val id = tpe match
384+
case tpe: AmbiguousImplicits => i"/* ambiguous: ${tpe.explanation} */"
385+
case _ => "/* missing */"
386386
SearchFailure(untpd.SearchFailureIdent(id.toTermName).withTypeUnchecked(tpe))
387387
}
388388
}
@@ -451,7 +451,7 @@ object Implicits {
451451
@sharable object NoMatchingImplicits extends NoMatchingImplicits(NoType, EmptyTree, OrderingConstraint.empty)
452452

453453
@sharable val NoMatchingImplicitsFailure: SearchFailure =
454-
SearchFailure(NoMatchingImplicits)(NoSource)
454+
SearchFailure(NoMatchingImplicits)(using NoContext)
455455

456456
/** An ambiguous implicits failure */
457457
class AmbiguousImplicits(val alt1: SearchSuccess, val alt2: SearchSuccess, val expectedType: Type, val argument: Tree) extends SearchFailureType {

tests/neg/i9185.check

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
-- [E008] Not Found Error: tests/neg/i9185.scala:7:21 ------------------------------------------------------------------
22
7 | val value2 = "ola".pure // error
33
| ^^^^^^^^^^
4-
| value pure is not a member of String.
5-
| An extension method was tried, but could not be fully constructed:
4+
|value pure is not a member of String.
5+
|An extension method was tried, but could not be fully constructed:
66
|
7-
| M.pure[A, F]("ola")(/* ambiguous */summon[M[F]])
7+
| M.pure[A, F]("ola")(
8+
| /* ambiguous: both object listMonad in object M and object optionMonad in object M match type M[F] */summon[M[F]]
9+
| )
810
-- Error: tests/neg/i9185.scala:8:26 -----------------------------------------------------------------------------------
911
8 | val value3 = pure("ola") // error
1012
| ^

0 commit comments

Comments
 (0)