File tree Expand file tree Collapse file tree 6 files changed +15
-6
lines changed
compiler/src/dotty/tools/dotc/reporting Expand file tree Collapse file tree 6 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -2913,11 +2913,20 @@ class MissingImplicitArgument(
29132913
29142914 def location (preposition : String ) = if (where.isEmpty) " " else s " $preposition $where"
29152915
2916+ /** Default error message for non-nested ambiguous implicits. */
29162917 def defaultAmbiguousImplicitMsg (ambi : AmbiguousImplicits ) =
29172918 s " Ambiguous given instances: ${ambi.explanation}${location(" of" )}"
29182919
2920+ /** Default error messages for non-ambiguous implicits, or nested ambiguous
2921+ * implicits.
2922+ *
2923+ * The default message is shown for ambiguous implicits only if they have
2924+ * the `nested` flag set. In this case, we output "no best given instance"
2925+ * instead of "no given instance".
2926+ */
29192927 def defaultImplicitNotFoundMessage =
2920- i " No given instance of type $pt was found ${location(" for" )}"
2928+ val bestStr = if arg.tpe.isInstanceOf [AmbiguousImplicits ] then " best" else " "
2929+ i " No $bestStr given instance of type $pt was found ${location(" for" )}"
29212930
29222931 /** Construct a custom error message given an ambiguous implicit
29232932 * candidate `alt` and a user defined message `raw`.
Original file line number Diff line number Diff line change 11-- [E172] Type Error: tests/neg/19414-desugared.scala:22:34 ------------------------------------------------------------
2222 | summon[BodySerializer[JsObject]] // error: Ambiguous given instances
33 | ^
4- |No given instance of type BodySerializer[JsObject] was found for parameter x of method summon in object Predef.
4+ |No best given instance of type BodySerializer[JsObject] was found for parameter x of method summon in object Predef.
55 |I found:
66 |
77 | given_BodySerializer_B[B](
Original file line number Diff line number Diff line change 11-- [E172] Type Error: tests/neg/19414.scala:15:34 ----------------------------------------------------------------------
2215 | summon[BodySerializer[JsObject]] // error: Ambiguous given instances
33 | ^
4- |No given instance of type BodySerializer[JsObject] was found for parameter x of method summon in object Predef.
4+ |No best given instance of type BodySerializer[JsObject] was found for parameter x of method summon in object Predef.
55 |I found:
66 |
77 | given_BodySerializer_B[B](
Original file line number Diff line number Diff line change 11-- [E172] Type Error: tests/neg/given-ambiguous-1.scala:12:23 ----------------------------------------------------------
2212 |def f: Unit = summon[B] // error: Ambiguous given instances
33 | ^
4- | No given instance of type B was found for parameter x of method summon in object Predef.
4+ | No best given instance of type B was found for parameter x of method summon in object Predef.
55 | I found:
66 |
77 | given_B(/* ambiguous: both given instance a1 and given instance a2 match type A */summon[A])
Original file line number Diff line number Diff line change 11-- [E172] Type Error: tests/neg/given-ambiguous-default-1.scala:18:23 --------------------------------------------------
2218 |def f: Unit = summon[B] // error: Ambiguous given instances
33 | ^
4- | No given instance of type B was found for parameter x of method summon in object Predef.
4+ | No best given instance of type B was found for parameter x of method summon in object Predef.
55 | I found:
66 |
77 | given_B(a = /* ambiguous: both given instance a1 and given instance a2 match type A */summon[A])
Original file line number Diff line number Diff line change 11-- [E172] Type Error: tests/neg/given-ambiguous-default-2.scala:18:23 --------------------------------------------------
2218 |def f: Unit = summon[C] // error: Ambiguous given instances
33 | ^
4- |No given instance of type C was found for parameter x of method summon in object Predef.
4+ |No best given instance of type C was found for parameter x of method summon in object Predef.
55 |I found:
66 |
77 | given_C(a = /* ambiguous: both given instance a1 and given instance a2 match type A */summon[A], this.given_C$default$2)
You can’t perform that action at this time.
0 commit comments