File tree 6 files changed +15
-6
lines changed
compiler/src/dotty/tools/dotc/reporting
6 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -2938,11 +2938,20 @@ class MissingImplicitArgument(
2938
2938
2939
2939
def location (preposition : String ) = if (where.isEmpty) " " else s " $preposition $where"
2940
2940
2941
+ /** Default error message for non-nested ambiguous implicits. */
2941
2942
def defaultAmbiguousImplicitMsg (ambi : AmbiguousImplicits ) =
2942
2943
s " Ambiguous given instances: ${ambi.explanation}${location(" of" )}"
2943
2944
2945
+ /** Default error messages for non-ambiguous implicits, or nested ambiguous
2946
+ * implicits.
2947
+ *
2948
+ * The default message is shown for ambiguous implicits only if they have
2949
+ * the `nested` flag set. In this case, we output "no best given instance"
2950
+ * instead of "no given instance".
2951
+ */
2944
2952
def defaultImplicitNotFoundMessage =
2945
- i " No given instance of type $pt was found ${location(" for" )}"
2953
+ val bestStr = if arg.tpe.isInstanceOf [AmbiguousImplicits ] then " best" else " "
2954
+ i " No $bestStr given instance of type $pt was found ${location(" for" )}"
2946
2955
2947
2956
/** Construct a custom error message given an ambiguous implicit
2948
2957
* candidate `alt` and a user defined message `raw`.
Original file line number Diff line number Diff line change 1
1
-- [E172] Type Error: tests/neg/19414-desugared.scala:22:34 ------------------------------------------------------------
2
2
22 | summon[BodySerializer[JsObject]] // error: Ambiguous given instances
3
3
| ^
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.
5
5
|I found:
6
6
|
7
7
| given_BodySerializer_B[B](
Original file line number Diff line number Diff line change 1
1
-- [E172] Type Error: tests/neg/19414.scala:15:34 ----------------------------------------------------------------------
2
2
15 | summon[BodySerializer[JsObject]] // error: Ambiguous given instances
3
3
| ^
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.
5
5
|I found:
6
6
|
7
7
| given_BodySerializer_B[B](
Original file line number Diff line number Diff line change 1
1
-- [E172] Type Error: tests/neg/given-ambiguous-1.scala:12:23 ----------------------------------------------------------
2
2
12 |def f: Unit = summon[B] // error: Ambiguous given instances
3
3
| ^
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.
5
5
| I found:
6
6
|
7
7
| 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 1
1
-- [E172] Type Error: tests/neg/given-ambiguous-default-1.scala:18:23 --------------------------------------------------
2
2
18 |def f: Unit = summon[B] // error: Ambiguous given instances
3
3
| ^
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.
5
5
| I found:
6
6
|
7
7
| 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 1
1
-- [E172] Type Error: tests/neg/given-ambiguous-default-2.scala:18:23 --------------------------------------------------
2
2
18 |def f: Unit = summon[C] // error: Ambiguous given instances
3
3
| ^
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.
5
5
|I found:
6
6
|
7
7
| 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