forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Typer#adaptNoArgsImplicitMethod populates implicit args when an arg list is missing. To remedy missing implicits, it tries a named application `using` args it did find. Then Applications#tryDefault supplies a default arg if available. A previous fix to allow tryDefault to supply implicit args for `implicit` params is now restricted to explicit `using`; typer now adds `using` for `implicit` when it needs to try defaults. This commit restores propagatedFailure and the previous condition that default params are tried if there is an error that is not an ambiguity. An additional restriction is that default params must be useful: there must be a param which has a default arg to be added (because it's not a named arg).
- Loading branch information
Showing
10 changed files
with
171 additions
and
95 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 |
---|---|---|
@@ -1,9 +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: | ||
| 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]) | ||
| 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. | ||
| 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
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 |
---|---|---|
@@ -1,8 +1,20 @@ | ||
-- [E172] Type Error: tests/neg/i19594.scala:12:14 --------------------------------------------------------------------- | ||
12 | assertEquals(true, 1, "values are not the same") // error | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| Can you see me?! | ||
-- [E172] Type Error: tests/neg/i19594.scala:13:14 --------------------------------------------------------------------- | ||
13 | assertEquals(true, 1) // error | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| Can you see me?! | ||
-- [E172] Type Error: tests/neg/i19594.scala:15:50 --------------------------------------------------------------------- | ||
15 | assertEquals(true, 1, "values are not the same") // error | ||
| ^ | ||
| Can you see me?! | ||
-- [E172] Type Error: tests/neg/i19594.scala:16:23 --------------------------------------------------------------------- | ||
16 | assertEquals(true, 1) // error | ||
| ^ | ||
| Can you see me?! | ||
-- [E172] Type Error: tests/neg/i19594.scala:20:12 --------------------------------------------------------------------- | ||
20 | f(true, 1) // error | ||
| ^ | ||
| Can you see me?! | ||
-- [E172] Type Error: tests/neg/i19594.scala:23:39 --------------------------------------------------------------------- | ||
23 | g(true, 1, "values are not the same") // error | ||
| ^ | ||
| Can you see me?! | ||
-- [E172] Type Error: tests/neg/i19594.scala:26:3 ---------------------------------------------------------------------- | ||
26 | h(true, 1) // error | ||
| ^^^^^^^^^^ | ||
| No given instance of type String was found |
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,22 @@ | ||
-- [E171] Type Error: tests/neg/i22439.scala:7:3 ----------------------------------------------------------------------- | ||
7 | f() // error f() missing arg | ||
| ^^^ | ||
| missing argument for parameter i of method f: (implicit i: Int, j: Int): Int | ||
-- [E050] Type Error: tests/neg/i22439.scala:8:2 ----------------------------------------------------------------------- | ||
8 | g() // error g(given_Int, given_Int)() doesn't take more params | ||
| ^ | ||
| method g does not take more parameters | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E171] Type Error: tests/neg/i22439.scala:11:3 ---------------------------------------------------------------------- | ||
11 | f(j = 27) // error missing argument for parameter i of method f | ||
| ^^^^^^^^^ | ||
| missing argument for parameter i of method f: (implicit i: Int, j: Int): Int | ||
-- [E172] Type Error: tests/neg/i22439.scala:16:3 ---------------------------------------------------------------------- | ||
16 | h // error | ||
| ^ | ||
| No given instance of type String was found for parameter s of method h | ||
-- [E172] Type Error: tests/neg/i22439.scala:17:3 ---------------------------------------------------------------------- | ||
17 | h(using i = 17) // error | ||
| ^^^^^^^^^^^^^^^ | ||
| No given instance of type String was found |
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,17 @@ | ||
|
||
@main def test() = println: | ||
given Int = 42 | ||
def f(implicit i: Int, j: Int) = i + j | ||
def g(using i: Int, j: Int) = i + j | ||
val x: Int = f | ||
f() // error f() missing arg | ||
g() // error g(given_Int, given_Int)() doesn't take more params | ||
f // ok implicits | ||
g // ok implicits | ||
f(j = 27) // error missing argument for parameter i of method f | ||
f(using j = 27) // ok, explicit supplemented by implicit | ||
g(using j = 27) // ok, explicit supplemented by implicit | ||
|
||
def h(using i: Int, s: String) = s * i | ||
h // error | ||
h(using i = 17) // error |
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 |
---|---|---|
@@ -1,18 +1,18 @@ | ||
|
||
case class A(x: String) | ||
case class B(x: String) | ||
given a1: A("default") | ||
given b1: B("default") | ||
val a2 = A("explicit") | ||
val b2 = B("explicit") | ||
given A("default") | ||
given B("default") | ||
val a = A("explicit") | ||
val b = B("explicit") | ||
|
||
def f(using a: A, b: B): Unit = | ||
println(a) | ||
println(b) | ||
|
||
@main def Test = | ||
f(using a2) | ||
f(using a = a2) | ||
f(using b = b2) | ||
f(using b = b2, a = a2) | ||
f(using a) | ||
f(using a = a) | ||
f(using b = b) | ||
f(using b = b, a = a) | ||
|