Skip to content

Commit 69ca72b

Browse files
oderskyWojciechMazur
authored andcommitted
Delay priority change until 3.7
Warnings from 3.6, change in 3.7. This is one version later than originally planned.
1 parent 069afba commit 69ca72b

20 files changed

+50
-31
lines changed

Diff for: compiler/src/dotty/tools/dotc/config/SourceVersion.scala

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ enum SourceVersion:
1212
case `3.4-migration`, `3.4`
1313
case `3.5-migration`, `3.5`
1414
case `3.6-migration`, `3.6`
15+
case `3.7-migration`, `3.7`
1516
// !!! Keep in sync with scala.runtime.stdlibPatches.language !!!
1617
case `future-migration`, `future`
1718

Diff for: compiler/src/dotty/tools/dotc/typer/Applications.scala

+7-7
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,7 @@ trait Applications extends Compatibility {
17531753
// and in mode Scala3-migration when we compare with the old Scala 2 rules.
17541754

17551755
case Intermediate // Intermediate rules: better means specialize, but map all type arguments downwards
1756-
// These are enabled for 3.0-3.4, or if OldImplicitResolution
1756+
// These are enabled for 3.0-3.5, or if OldImplicitResolution
17571757
// is specified, and also for all comparisons between old-style implicits,
17581758

17591759
case New // New rules: better means generalize, givens (and extensions) always beat implicits
@@ -1789,7 +1789,7 @@ trait Applications extends Compatibility {
17891789
val oldResolution = ctx.mode.is(Mode.OldImplicitResolution)
17901790
if !preferGeneral || Feature.migrateTo3 && oldResolution then
17911791
CompareScheme.Old
1792-
else if Feature.sourceVersion.isAtMost(SourceVersion.`3.4`)
1792+
else if Feature.sourceVersion.isAtMost(SourceVersion.`3.5`)
17931793
|| oldResolution
17941794
|| alt1.symbol.is(Implicit) && alt2.symbol.is(Implicit)
17951795
then CompareScheme.Intermediate
@@ -1855,7 +1855,7 @@ trait Applications extends Compatibility {
18551855
* available in 3.0-migration if mode `Mode.OldImplicitResolution` is turned on as well.
18561856
* It is used to highlight differences between Scala 2 and 3 behavior.
18571857
*
1858-
* - In Scala 3.0-3.5, the behavior is as follows: `T <:p U` iff there is an impliit conversion
1858+
* - In Scala 3.0-3.6, the behavior is as follows: `T <:p U` iff there is an implicit conversion
18591859
* from `T` to `U`, or
18601860
*
18611861
* flip(T) <: flip(U)
@@ -1870,14 +1870,14 @@ trait Applications extends Compatibility {
18701870
* of parameters are not affected. So `T <: U` would imply `Set[Cmp[U]] <:p Set[Cmp[T]]`,
18711871
* as usual, because `Set` is non-variant.
18721872
*
1873-
* - From Scala 3.6, `T <:p U` means `T <: U` or `T` convertible to `U`
1873+
* - From Scala 3.7, `T <:p U` means `T <: U` or `T` convertible to `U`
18741874
* for overloading resolution (when `preferGeneral is false), and the opposite relation
18751875
* `U <: T` or `U convertible to `T` for implicit disambiguation between givens
1876-
* (when `preferGeneral` is true). For old-style implicit values, the 3.4 behavior is kept.
1876+
* (when `preferGeneral` is true). For old-style implicit values, the 3.5 behavior is kept.
18771877
* If one of the alternatives is an implicit and the other is a given (or an extension), the implicit loses.
18781878
*
1879-
* - In Scala 3.5 and Scala 3.6-migration, we issue a warning if the result under
1880-
* Scala 3.6 differ wrt to the old behavior up to 3.5.
1879+
* - In Scala 3.6 and Scala 3.7-migration, we issue a warning if the result under
1880+
* Scala 3.7 differs wrt to the old behavior up to 3.6.
18811881
*
18821882
* Also and only for given resolution: If a compared type refers to a given or its module class, use
18831883
* the intersection of its parent classes instead.

Diff for: compiler/src/dotty/tools/dotc/typer/Implicits.scala

+9-9
Original file line numberDiff line numberDiff line change
@@ -1305,26 +1305,26 @@ trait Implicits:
13051305
/** Search a list of eligible implicit references */
13061306
private def searchImplicit(eligible: List[Candidate], contextual: Boolean): SearchResult =
13071307

1308-
// A map that associates a priority change warning (between -source 3.4 and 3.6)
1308+
// A map that associates a priority change warning (between -source 3.6 and 3.7)
13091309
// with the candidate refs mentioned in the warning. We report the associated
13101310
// message if one of the critical candidates is part of the result of the implicit search.
13111311
val priorityChangeWarnings = mutable.ListBuffer[(/*critical:*/ List[TermRef], Message)]()
13121312

13131313
def isWarnPriorityChangeVersion(sv: SourceVersion): Boolean =
1314-
sv.stable == SourceVersion.`3.5` || sv == SourceVersion.`3.6-migration`
1314+
sv.stable == SourceVersion.`3.6` || sv == SourceVersion.`3.7-migration`
13151315

13161316
/** Compare `alt1` with `alt2` to determine which one should be chosen.
13171317
*
13181318
* @return a number > 0 if `alt1` is preferred over `alt2`
13191319
* a number < 0 if `alt2` is preferred over `alt1`
13201320
* 0 if neither alternative is preferred over the other
13211321
* The behavior depends on the source version
1322-
* before 3.5: compare with preferGeneral = false
1323-
* 3.5: compare twice with preferGeneral = false and true, warning if result is different,
1322+
* before 3.6: compare with preferGeneral = false
1323+
* 3.6: compare twice with preferGeneral = false and true, warning if result is different,
13241324
* return old result with preferGeneral = false
1325-
* 3.6-migration: compare twice with preferGeneral = false and true, warning if result is different,
1325+
* 3.7-migration: compare twice with preferGeneral = false and true, warning if result is different,
13261326
* return new result with preferGeneral = true
1327-
* 3.6 and higher: compare with preferGeneral = true
1327+
* 3.7 and higher: compare with preferGeneral = true
13281328
*
13291329
* @param disambiguate The call is used to disambiguate two successes, not for ranking.
13301330
* When ranking, we are always filtering out either > 0 or <= 0 results.
@@ -1348,15 +1348,15 @@ trait Implicits:
13481348
case -1 => "the second alternative"
13491349
case 1 => "the first alternative"
13501350
case _ => "none - it's ambiguous"
1351-
if sv.stable == SourceVersion.`3.5` then
1351+
if sv.stable == SourceVersion.`3.6` then
13521352
warn(
13531353
em"""Given search preference for $pt between alternatives
13541354
| ${alt1.ref}
13551355
|and
13561356
| ${alt2.ref}
13571357
|will change.
13581358
|Current choice : ${choice(prev)}
1359-
|New choice from Scala 3.6: ${choice(cmp)}""")
1359+
|New choice from Scala 3.7: ${choice(cmp)}""")
13601360
prev
13611361
else
13621362
warn(
@@ -1366,7 +1366,7 @@ trait Implicits:
13661366
| ${alt2.ref}
13671367
|has changed.
13681368
|Previous choice : ${choice(prev)}
1369-
|New choice from Scala 3.6: ${choice(cmp)}""")
1369+
|New choice from Scala 3.7: ${choice(cmp)}""")
13701370
cmp
13711371
else cmp max prev
13721372
// When ranking, we keep the better of cmp and prev, which ends up retaining a candidate

Diff for: library/src/scala/runtime/stdLibPatches/language.scala

+15
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,21 @@ object language:
300300
@compileTimeOnly("`3.6` can only be used at compile time in import statements")
301301
object `3.6`
302302

303+
/** Set source version to 3.7-migration.
304+
*
305+
* @see [[https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html]]
306+
*/
307+
@compileTimeOnly("`3.7-migration` can only be used at compile time in import statements")
308+
object `3.7-migration`
309+
310+
/** Set source version to 3.7
311+
*
312+
* @see [[https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html]]
313+
*/
314+
@compileTimeOnly("`3.7` can only be used at compile time in import statements")
315+
object `3.7`
316+
317+
303318
// !!! Keep in sync with dotty.tools.dotc.config.SourceVersion !!!
304319
// Also add tests in `tests/pos/source-import-3-x.scala` and `tests/pos/source-import-3-x-migration.scala`
305320

Diff for: tests/neg/given-triangle.check

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
| (given_B : B)
1010
|will change.
1111
|Current choice : the second alternative
12-
|New choice from Scala 3.6: the first alternative
12+
|New choice from Scala 3.7: the first alternative

Diff for: tests/neg/given-triangle.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//> using options -source 3.5
1+
//> using options -source 3.6
22
class A
33
class B extends A
44
class C extends A

Diff for: tests/neg/i15264.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import language.`3.6`
1+
import language.`3.7`
22
object priority:
33
// lower number = higher priority
44
class Prio0 extends Prio1

Diff for: tests/neg/i21212.check

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- [E172] Type Error: tests/neg/i21212.scala:8:52 ----------------------------------------------------------------------
2-
8 | def test2(using a2: A)(implicit b2: B) = summon[A] // error: ambiguous
1+
-- [E172] Type Error: tests/neg/i21212.scala:9:52 ----------------------------------------------------------------------
2+
9 | def test2(using a2: A)(implicit b2: B) = summon[A] // error: ambiguous
33
| ^
44
|Ambiguous given instances: both parameter b2 and parameter a2 match type Minimization.A of parameter x of method summon in object Predef

Diff for: tests/neg/i21212.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//> using options -source:3.6
1+
//> using options -source 3.7
2+
23
object Minimization:
34

45
trait A

Diff for: tests/neg/i21303/Test.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//> using options -source 3.6-migration
1+
//> using options -source 3.7-migration
22
import scala.deriving.Mirror
33
import scala.compiletime.*
44
import scala.reflect.ClassTag

Diff for: tests/pos/source-import-3-7-migration.scala

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import language.`3.7-migration`

Diff for: tests/pos/source-import-3-7.scala

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import language.`3.7`

Diff for: tests/run/given-triangle.scala

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

33
class A
44
class B extends A

Diff for: tests/run/implicit-specifity.scala

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

33
case class Show[T](val i: Int)
44
object Show {

Diff for: tests/run/implied-priority.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* These tests show various mechanisms available for implicit prioritization.
22
*/
3-
import language.`3.6`
3+
import language.`3.7`
44

55
class E[T](val str: String) // The type for which we infer terms below
66

Diff for: tests/warn/i20420.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//> using options -source 3.5-migration
1+
//> using options -source 3.6-migration
22

33
final class StrictEqual[V]
44
final class Less[V]

Diff for: tests/warn/i21036a.check

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
| (a : A)
88
| will change.
99
| Current choice : the first alternative
10-
| New choice from Scala 3.6: the second alternative
10+
| New choice from Scala 3.7: the second alternative

Diff for: tests/warn/i21036a.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//> using options -source 3.5
1+
//> using options -source 3.6
22
trait A
33
trait B extends A
44
given b: B = ???

Diff for: tests/warn/i21036b.check

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
| (a : A)
88
| has changed.
99
| Previous choice : the first alternative
10-
| New choice from Scala 3.6: the second alternative
10+
| New choice from Scala 3.7: the second alternative

Diff for: tests/warn/i21036b.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//> using options -source 3.6-migration
1+
//> using options -source 3.7-migration
22
trait A
33
trait B extends A
44
given b: B = ???

0 commit comments

Comments
 (0)