-
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.
Test overloading changes and reported warning messages
Note that in tests/neg/multiparamlist-overload-3.7 Test2 we now get an error in both Parts as intended. But they are, however, different ones: Part1 is a TypeMismatch Error, whereas Part2 is a NoMatchingOverload Error. This is due to the fact that `resolveOverloaded` will first find the candidate alternatives by considering only the 1st parameter list and commit early if there is a single one, e.g. Test2.Part1. If not, we recursively continue with the found alternatives and recompute the candidate alternatives based on the 2nd parameter list, which may rule out all of them, and hence lead to a different message.
- Loading branch information
1 parent
2e0cff0
commit f40c609
Showing
8 changed files
with
219 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
-- [E007] Type Mismatch Error: tests/neg/multiparamlist-overload-3.6.scala:33:21 --------------------------------------- | ||
33 | val r = f(new B)(new A) // error since resolves to R2 in 3.6 (and 3.7) as expected | ||
| ^^^^^ | ||
| Found: A | ||
| Required: B | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- Warning: tests/neg/multiparamlist-overload-3.6.scala:20:10 ---------------------------------------------------------- | ||
20 | val r = f(new B)(new C) // resolves to R1 in 3.6 | ||
| ^ | ||
| Overloading resolution for arguments (B)(C) between alternatives | ||
| (x: B)(y: B): R3 | ||
| (x: B)(y: A): R2 | ||
| (x: A)(y: C): R1 | ||
| will change. | ||
| Current choice : (x: A)(y: C): R1 | ||
| New choice from Scala 3.7: (x: B)(y: B): R3 | ||
-- Warning: tests/neg/multiparamlist-overload-3.6.scala:40:12 ---------------------------------------------------------- | ||
40 | val r = f(new B)(new A) // resolves to R1 in 3.6 | ||
| ^ | ||
| Overloading resolution for arguments (B)(A) between alternatives | ||
| (x: B)(y: C): R3 | ||
| (x: B)(y: B): R2 | ||
| (x: A)(y: A): R1 | ||
| will change. | ||
| Current choice : (x: A)(y: A): R1 | ||
| New choice from Scala 3.7: none |
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,43 @@ | ||
import scala.language.`3.6` | ||
|
||
class A | ||
class B extends A | ||
class C extends B | ||
|
||
class R1 | ||
class R2 | ||
class R3 | ||
|
||
// The alternatives are ordered from most genereal to most specific in each test, | ||
// with respect to a lexicographic ordering by parameter list. | ||
|
||
|
||
object Test1: | ||
def f(x: A)(y: C) = new R1 | ||
def f(x: B)(y: A) = new R2 | ||
def f(x: B)(y: B) = new R3 | ||
|
||
val r = f(new B)(new C) // resolves to R1 in 3.6 | ||
val _: R1 = r | ||
end Test1 | ||
|
||
|
||
object Test2: | ||
// R1 is the only applicable alternative in both parts | ||
// but it is only resolved to in Part2 by adding (an unapplicable) R3 | ||
|
||
object Part1: | ||
def f(x: A)(y: A) = new R1 | ||
def f(x: B)(y: B) = new R2 | ||
|
||
val r = f(new B)(new A) // error since resolves to R2 in 3.6 (and 3.7) as expected | ||
|
||
object Part2: | ||
def f(x: A)(y: A) = new R1 | ||
def f(x: B)(y: B) = new R2 | ||
def f(x: B)(y: C) = new R3 | ||
|
||
val r = f(new B)(new A) // resolves to R1 in 3.6 | ||
val _: R1 = r | ||
|
||
end Test2 |
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,25 @@ | ||
-- [E007] Type Mismatch Error: tests/neg/multiparamlist-overload-3.7.scala:33:21 --------------------------------------- | ||
33 | val r = f(new B)(new A) // error since resolves to R2 in 3.7 (and 3.6), as expected | ||
| ^^^^^ | ||
| Found: A | ||
| Required: B | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E134] Type Error: tests/neg/multiparamlist-overload-3.7.scala:40:12 ------------------------------------------------ | ||
40 | val r = f(new B)(new A) // error since resolves to R2 in 3.7, as in Part1 | ||
| ^ | ||
| None of the overloaded alternatives of method f in object Part2 with types | ||
| (x: B)(y: C): R3 | ||
| (x: B)(y: B): R2 | ||
| (x: A)(y: A): R1 | ||
| match arguments (B)(A) | ||
-- Warning: tests/neg/multiparamlist-overload-3.7.scala:20:10 ---------------------------------------------------------- | ||
20 | val r = f(new B)(new C) // resolves to R3 in 3.7 | ||
| ^ | ||
| Overloading resolution for arguments (B)(C) between alternatives | ||
| (x: B)(y: B): R3 | ||
| (x: B)(y: A): R2 | ||
| (x: A)(y: C): R1 | ||
| has changed. | ||
| Previous choice : (x: A)(y: C): R1 | ||
| New choice from Scala 3.7: (x: B)(y: B): R3 |
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,42 @@ | ||
import scala.language.`3.7-migration` | ||
|
||
class A | ||
class B extends A | ||
class C extends B | ||
|
||
class R1 | ||
class R2 | ||
class R3 | ||
|
||
// The alternatives are ordered from most genereal to most specific in each test, | ||
// with respect to a lexicographic ordering by parameter list. | ||
|
||
|
||
object Test1: | ||
def f(x: A)(y: C) = new R1 | ||
def f(x: B)(y: A) = new R2 | ||
def f(x: B)(y: B) = new R3 | ||
|
||
val r = f(new B)(new C) // resolves to R3 in 3.7 | ||
val _: R3 = r | ||
end Test1 | ||
|
||
|
||
object Test2: | ||
// R1 is the only applicable alternative in both parts | ||
// but it is never resolved to since R2 has a more specific 1st parameter list | ||
|
||
object Part1: | ||
def f(x: A)(y: A) = new R1 | ||
def f(x: B)(y: B) = new R2 | ||
|
||
val r = f(new B)(new A) // error since resolves to R2 in 3.7 (and 3.6), as expected | ||
|
||
object Part2: | ||
def f(x: A)(y: A) = new R1 | ||
def f(x: B)(y: B) = new R2 | ||
def f(x: B)(y: C) = new R3 | ||
|
||
val r = f(new B)(new A) // error since resolves to R2 in 3.7, as in Part1 | ||
|
||
end Test2 |
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 @@ | ||
import scala.language.`3.7` | ||
|
||
class TestBody1 | ||
class TestBody2 | ||
|
||
class StartWithWord | ||
class EndWithWord | ||
|
||
class Matchers: | ||
extension (leftSideString: String) | ||
def should(body: TestBody1): Unit = () | ||
def should(body: TestBody2): Unit = () | ||
|
||
extension [T](leftSideValue: T) | ||
def should(word: StartWithWord)(using T <:< String): Unit = () | ||
def should(word: EndWithWord)(using T <:< String): Unit = () | ||
|
||
def endWith(rightSideString: String): EndWithWord = new EndWithWord | ||
|
||
class Test extends Matchers: | ||
def test(): Unit = | ||
"hello world" should endWith ("world") // 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import scala.language.`3.6` | ||
|
||
class TestBody1 | ||
class TestBody2 | ||
|
||
class StartWithWord | ||
class EndWithWord | ||
|
||
class Matchers: | ||
extension (leftSideString: String) | ||
def should(body: TestBody1): Unit = () | ||
def should(body: TestBody2): Unit = () | ||
|
||
extension [T](leftSideValue: T) | ||
def should(word: StartWithWord)(using T <:< String): Unit = () | ||
def should(word: EndWithWord)(using T <:< String): Unit = () | ||
|
||
def endWith(rightSideString: String): EndWithWord = new EndWithWord | ||
|
||
class Test extends Matchers: | ||
def test(): Unit = | ||
"hello world" should endWith ("world") // ok, error in 3.7 |