-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport "Fix implicit search failure reporting" to LTS (#21089)
Backports #20261 to the LTS branch. PR submitted by the release tooling. [skip ci]
- Loading branch information
Showing
15 changed files
with
210 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- [E172] Type Error: tests/neg/19414-desugared.scala:22:34 ------------------------------------------------------------ | ||
22 | summon[BodySerializer[JsObject]] // error: Ambiguous given instances | ||
| ^ | ||
|No best given instance of type BodySerializer[JsObject] was found for parameter x of method summon in object Predef. | ||
|I found: | ||
| | ||
| given_BodySerializer_B[B]( | ||
| writer = | ||
| /* ambiguous: both given instance given_Writer_JsValue and given instance given_Writer_JsObject match type Writer[B] */ | ||
| summon[Writer[B]] | ||
| , | ||
| this.given_BodySerializer_B$default$2[B]) | ||
| | ||
|But both given instance given_Writer_JsValue and given instance given_Writer_JsObject match type Writer[B]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
trait JsValue | ||
trait JsObject extends JsValue | ||
|
||
trait Writer[T] | ||
trait BodySerializer[-B] | ||
|
||
class Printer | ||
|
||
given Writer[JsValue] = ??? | ||
given Writer[JsObject] = ??? | ||
|
||
// This is not an exact desugaring of the original code: currently the compiler | ||
// actually changes the modifier of the parameter list from `using` to | ||
// `implicit` when desugaring the context-bound `B: Writer` to `implicit writer: | ||
// Writer[B]`, but we can't write it in user code as this is not valid syntax. | ||
given [B](using | ||
writer: Writer[B], | ||
printer: Printer = new Printer | ||
): BodySerializer[B] = ??? | ||
|
||
def f: Unit = | ||
summon[BodySerializer[JsObject]] // error: Ambiguous given instances |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- [E172] Type Error: tests/neg/19414.scala:15:34 ---------------------------------------------------------------------- | ||
15 | summon[BodySerializer[JsObject]] // error: Ambiguous given instances | ||
| ^ | ||
|No best given instance of type BodySerializer[JsObject] was found for parameter x of method summon in object Predef. | ||
|I found: | ||
| | ||
| given_BodySerializer_B[B]( | ||
| evidence$1 = | ||
| /* ambiguous: both given instance given_Writer_JsValue and given instance given_Writer_JsObject match type Writer[B] */ | ||
| summon[Writer[B]] | ||
| , | ||
| this.given_BodySerializer_B$default$2[B]) | ||
| | ||
|But both given instance given_Writer_JsValue and given instance given_Writer_JsObject match type Writer[B]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
trait JsValue | ||
trait JsObject extends JsValue | ||
|
||
trait Writer[T] | ||
trait BodySerializer[-B] | ||
|
||
class Printer | ||
|
||
given Writer[JsValue] = ??? | ||
given Writer[JsObject] = ??? | ||
|
||
given [B: Writer](using printer: Printer = new Printer): BodySerializer[B] = ??? | ||
|
||
def f: Unit = | ||
summon[BodySerializer[JsObject]] // error: Ambiguous given instances |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-- [E172] Type Error: tests/neg/given-ambiguous-1.scala:12:23 ---------------------------------------------------------- | ||
12 |def f: Unit = summon[B] // error: Ambiguous given instances | ||
| ^ | ||
| No best given instance of type B was found for parameter x of method summon in object Predef. | ||
| I found: | ||
| | ||
| given_B(/* ambiguous: both given instance a1 and given instance a2 match type A */summon[A]) | ||
| | ||
| But both given instance a1 and given instance a2 match type A. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class A | ||
class B | ||
given a1: A = ??? | ||
given a2: A = ??? | ||
given (using a: A): B = ??? | ||
|
||
// In this case, the ambiguous given instance is not directly the argument of | ||
// `summon`; it is the argument of `given_B` which is needed for the argument of | ||
// `summon`. This is a nested ambiguous implicit, thus we report an error in | ||
// the style "I found ... but". See `given-ambiguous-2` for a direct ambiguous | ||
// implicit error. | ||
def f: Unit = summon[B] // error: Ambiguous given instances |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-- [E172] Type Error: tests/neg/given-ambiguous-2.scala:10:15 ---------------------------------------------------------- | ||
10 |def f: Unit = g // error: Ambiguous given instances | ||
| ^ | ||
| Ambiguous given instances: both given instance a1 and given instance a2 match type A of parameter a of method g |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class A | ||
class B | ||
given a1: A = ??? | ||
given a2: A = ??? | ||
def g(using a: A): B = ??? | ||
|
||
// In this case, the ambiguous given instance is directly the argument of | ||
// `summon`. This is a direct ambiguous implicit, thus we report the error | ||
// directly. See `given-ambiguous-1` for a nested ambiguous implicit error. | ||
def f: Unit = g // error: Ambiguous given instances |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-- [E172] Type Error: tests/neg/given-ambiguous-default-1.scala:18:23 -------------------------------------------------- | ||
18 |def f: Unit = summon[B] // error: Ambiguous given instances | ||
| ^ | ||
| No best given instance of type B was found for parameter x of method summon in object Predef. | ||
| I found: | ||
| | ||
| given_B(a = /* ambiguous: both given instance a1 and given instance a2 match type A */summon[A]) | ||
| | ||
| But both given instance a1 and given instance a2 match type A. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** This test checks that provided ambiguous given instances take precedence | ||
* over default given arguments. In the following code, the compiler must | ||
* report an "Ambiguous implicits" error for the parameter `a`, and must not | ||
* use its default value. | ||
* | ||
* See also: | ||
* - tests/neg/19414.scala | ||
* - tests/neg/19414-desugared.scala | ||
* - tests/neg/given-ambiguous-default-2.scala | ||
*/ | ||
|
||
class A | ||
class B | ||
given a1: A = ??? | ||
given a2: A = ??? | ||
given (using a: A = A()): B = ??? | ||
|
||
def f: Unit = summon[B] // error: Ambiguous given instances |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-- [E172] Type Error: tests/neg/given-ambiguous-default-2.scala:18:23 -------------------------------------------------- | ||
18 |def f: Unit = summon[C] // error: Ambiguous given instances | ||
| ^ | ||
|No best given instance of type C was found for parameter x of method summon in object Predef. | ||
|I found: | ||
| | ||
| given_C(a = /* ambiguous: both given instance a1 and given instance a2 match type A */summon[A], this.given_C$default$2) | ||
| | ||
|But both given instance a1 and given instance a2 match type A. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** This test checks that provided given instances take precedence over default | ||
* given arguments, even when there are multiple default arguments. Before the | ||
* fix for issue #19414, this code would compile without errors. | ||
* | ||
* See also: | ||
* - tests/neg/given-ambiguous-default-1.scala | ||
* - tests/neg/19414.scala | ||
* - tests/neg/19414-desugared.scala | ||
*/ | ||
|
||
class A | ||
class B | ||
class C | ||
given a1: A = ??? | ||
given a2: A = ??? | ||
given (using a: A = A(), b: B = B()): C = ??? | ||
|
||
def f: Unit = summon[C] // error: Ambiguous given instances |