Skip to content

Commit e8b9cee

Browse files
Delay overloading priority changes to 3.8
With the warnings about the changes enabled in 3.7 and 3.8-migration
1 parent 6d05485 commit e8b9cee

6 files changed

+21
-22
lines changed

compiler/src/dotty/tools/dotc/typer/Applications.scala

+6-7
Original file line numberDiff line numberDiff line change
@@ -2226,18 +2226,20 @@ trait Applications extends Compatibility {
22262226
record(s"resolveOverloaded1", alts.length)
22272227

22282228
val sv = Feature.sourceVersion
2229-
val isOldPriorityVersion: Boolean = sv.isAtMost(SourceVersion.`3.6`)
2230-
val isWarnPriorityChangeVersion = sv == SourceVersion.`3.6` || sv == SourceVersion.`3.7-migration`
2229+
val isOldPriorityVersion: Boolean = sv.isAtMost(SourceVersion.`3.7`)
2230+
val isWarnPriorityChangeVersion = sv == SourceVersion.`3.7` || sv == SourceVersion.`3.8-migration`
22312231

2232-
inline def warnOnPriorityChange(oldCands: List[TermRef], newCands: List[TermRef])(f: List[TermRef] => List[TermRef]): List[TermRef] =
2232+
def warnOnPriorityChange(oldCands: List[TermRef], newCands: List[TermRef])(f: List[TermRef] => List[TermRef]): List[TermRef] =
2233+
lazy val oldRes = f(oldCands)
2234+
val newRes = f(newCands)
22332235

22342236
def doWarn(oldChoice: String, newChoice: String): Unit =
22352237
val (change, whichChoice) =
22362238
if isOldPriorityVersion
22372239
then ("will change", "Current choice ")
22382240
else ("has changed", "Previous choice")
22392241

2240-
val msg = // uses oldCands as the list of alternatives since they should be a superset of newCands
2242+
val msg = // using oldCands to list the alternatives as they should be a superset of newCands
22412243
em"""Overloading resolution for ${err.expectedTypeStr(pt)} between alternatives
22422244
| ${oldCands map (_.info)}%\n %
22432245
|$change.
@@ -2247,9 +2249,6 @@ trait Applications extends Compatibility {
22472249
report.warning(msg, srcPos)
22482250
end doWarn
22492251

2250-
lazy val oldRes = f(oldCands)
2251-
val newRes = f(newCands)
2252-
22532252
if isWarnPriorityChangeVersion then (oldRes, newRes) match
22542253
case (oldAlt :: Nil, newAlt :: Nil) if oldAlt != newAlt => doWarn(oldAlt.info.show, newAlt.info.show)
22552254
case (oldAlt :: Nil, Nil) => doWarn(oldAlt.info.show, "none")

tests/neg/multiparamlist-overload-3.6.check

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
-- [E007] Type Mismatch Error: tests/neg/multiparamlist-overload-3.6.scala:33:21 ---------------------------------------
2-
33 | val r = f(new B)(new A) // error since resolves to R2 in 3.6 (and 3.7) as expected
2+
33 | val r = f(new B)(new A) // error since resolves to R2 in 3.7 (and 3.8) as expected
33
| ^^^^^
44
| Found: A
55
| Required: B
66
|
77
| longer explanation available when compiling with `-explain`
88
-- Warning: tests/neg/multiparamlist-overload-3.6.scala:20:10 ----------------------------------------------------------
9-
20 | val r = f(new B)(new C) // resolves to R1 in 3.6
9+
20 | val r = f(new B)(new C) // resolves to: R1 in 3.7, R3 in 3.8
1010
| ^
1111
| Overloading resolution for arguments (B)(C) between alternatives
1212
| (x: B)(y: B): R3
@@ -16,7 +16,7 @@
1616
| Current choice : (x: A)(y: C): R1
1717
| New choice from Scala 3.7: (x: B)(y: B): R3
1818
-- Warning: tests/neg/multiparamlist-overload-3.6.scala:40:12 ----------------------------------------------------------
19-
40 | val r = f(new B)(new A) // resolves to R1 in 3.6
19+
40 | val r = f(new B)(new A) // resolves to: R1 in 3.7, R2 in 3.8 as in Part1
2020
| ^
2121
| Overloading resolution for arguments (B)(A) between alternatives
2222
| (x: B)(y: C): R3

tests/neg/multiparamlist-overload-3.6.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.language.`3.6`
1+
import scala.language.`3.7`
22

33
class A
44
class B extends A
@@ -17,7 +17,7 @@ object Test1:
1717
def f(x: B)(y: A) = new R2
1818
def f(x: B)(y: B) = new R3
1919

20-
val r = f(new B)(new C) // resolves to R1 in 3.6
20+
val r = f(new B)(new C) // resolves to: R1 in 3.7, R3 in 3.8
2121
val _: R1 = r
2222
end Test1
2323

@@ -30,14 +30,14 @@ object Test2:
3030
def f(x: A)(y: A) = new R1
3131
def f(x: B)(y: B) = new R2
3232

33-
val r = f(new B)(new A) // error since resolves to R2 in 3.6 (and 3.7) as expected
33+
val r = f(new B)(new A) // error since resolves to R2 in 3.7 (and 3.8) as expected
3434

3535
object Part2:
3636
def f(x: A)(y: A) = new R1
3737
def f(x: B)(y: B) = new R2
3838
def f(x: B)(y: C) = new R3
3939

40-
val r = f(new B)(new A) // resolves to R1 in 3.6
40+
val r = f(new B)(new A) // resolves to: R1 in 3.7, R2 in 3.8 as in Part1
4141
val _: R1 = r
4242

4343
end Test2

tests/neg/multiparamlist-overload-3.7.check

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
-- [E007] Type Mismatch Error: tests/neg/multiparamlist-overload-3.7.scala:33:21 ---------------------------------------
2-
33 | val r = f(new B)(new A) // error since resolves to R2 in 3.7 (and 3.6), as expected
2+
33 | val r = f(new B)(new A) // error, since resolves to R2 in both 3.7 and 3.8, as expected
33
| ^^^^^
44
| Found: A
55
| Required: B
66
|
77
| longer explanation available when compiling with `-explain`
88
-- [E134] Type Error: tests/neg/multiparamlist-overload-3.7.scala:40:12 ------------------------------------------------
9-
40 | val r = f(new B)(new A) // error since resolves to R2 in 3.7, as in Part1
9+
40 | val r = f(new B)(new A) // error since resolves to R2 in 3.8 as in Part1 (was R1 in 3.7)
1010
| ^
1111
| None of the overloaded alternatives of method f in object Part2 with types
1212
| (x: B)(y: C): R3
1313
| (x: B)(y: B): R2
1414
| (x: A)(y: A): R1
1515
| match arguments (B)(A)
1616
-- Warning: tests/neg/multiparamlist-overload-3.7.scala:20:10 ----------------------------------------------------------
17-
20 | val r = f(new B)(new C) // resolves to R3 in 3.7
17+
20 | val r = f(new B)(new C) // resolves to: R1 in 3.7, R3 in 3.8
1818
| ^
1919
| Overloading resolution for arguments (B)(C) between alternatives
2020
| (x: B)(y: B): R3

tests/neg/multiparamlist-overload-3.7.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.language.`3.7-migration`
1+
import scala.language.`3.8-migration`
22

33
class A
44
class B extends A
@@ -17,7 +17,7 @@ object Test1:
1717
def f(x: B)(y: A) = new R2
1818
def f(x: B)(y: B) = new R3
1919

20-
val r = f(new B)(new C) // resolves to R3 in 3.7
20+
val r = f(new B)(new C) // resolves to: R1 in 3.7, R3 in 3.8
2121
val _: R3 = r
2222
end Test1
2323

@@ -30,13 +30,13 @@ object Test2:
3030
def f(x: A)(y: A) = new R1
3131
def f(x: B)(y: B) = new R2
3232

33-
val r = f(new B)(new A) // error since resolves to R2 in 3.7 (and 3.6), as expected
33+
val r = f(new B)(new A) // error, since resolves to R2 in both 3.7 and 3.8, as expected
3434

3535
object Part2:
3636
def f(x: A)(y: A) = new R1
3737
def f(x: B)(y: B) = new R2
3838
def f(x: B)(y: C) = new R3
3939

40-
val r = f(new B)(new A) // error since resolves to R2 in 3.7, as in Part1
40+
val r = f(new B)(new A) // error since resolves to R2 in 3.8 as in Part1 (was R1 in 3.7)
4141

4242
end Test2

tests/neg/scalatest-overload-3.7.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.language.`3.7`
1+
import scala.language.`3.8`
22

33
class TestBody1
44
class TestBody2

0 commit comments

Comments
 (0)