Skip to content

Commit

Permalink
Delay priority change until 3.7
Browse files Browse the repository at this point in the history
Warnings from 3.6, change in 3.7. This is one version later than
originally planned.
  • Loading branch information
odersky committed Aug 5, 2024
1 parent 37dd612 commit 6b1f49f
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 30 deletions.
14 changes: 7 additions & 7 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1767,7 +1767,7 @@ trait Applications extends Compatibility {
// and in mode Scala3-migration when we compare with the old Scala 2 rules.

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

case New // New rules: better means generalize, givens (and extensions) always beat implicits
Expand Down Expand Up @@ -1803,7 +1803,7 @@ trait Applications extends Compatibility {
val oldResolution = ctx.mode.is(Mode.OldImplicitResolution)
if !preferGeneral || Feature.migrateTo3 && oldResolution then
CompareScheme.Old
else if Feature.sourceVersion.isAtMost(SourceVersion.`3.4`)
else if Feature.sourceVersion.isAtMost(SourceVersion.`3.5`)
|| oldResolution
|| alt1.symbol.is(Implicit) && alt2.symbol.is(Implicit)
then CompareScheme.Intermediate
Expand Down Expand Up @@ -1869,7 +1869,7 @@ trait Applications extends Compatibility {
* available in 3.0-migration if mode `Mode.OldImplicitResolution` is turned on as well.
* It is used to highlight differences between Scala 2 and 3 behavior.
*
* - In Scala 3.0-3.5, the behavior is as follows: `T <:p U` iff there is an implicit conversion
* - In Scala 3.0-3.6, the behavior is as follows: `T <:p U` iff there is an implicit conversion
* from `T` to `U`, or
*
* flip(T) <: flip(U)
Expand All @@ -1884,14 +1884,14 @@ trait Applications extends Compatibility {
* of parameters are not affected. So `T <: U` would imply `Set[Cmp[U]] <:p Set[Cmp[T]]`,
* as usual, because `Set` is non-variant.
*
* - From Scala 3.6, `T <:p U` means `T <: U` or `T` convertible to `U`
* - From Scala 3.7, `T <:p U` means `T <: U` or `T` convertible to `U`
* for overloading resolution (when `preferGeneral is false), and the opposite relation
* `U <: T` or `U convertible to `T` for implicit disambiguation between givens
* (when `preferGeneral` is true). For old-style implicit values, the 3.4 behavior is kept.
* (when `preferGeneral` is true). For old-style implicit values, the 3.5 behavior is kept.
* If one of the alternatives is an implicit and the other is a given (or an extension), the implicit loses.
*
* - In Scala 3.5 and Scala 3.6-migration, we issue a warning if the result under
* Scala 3.6 differ wrt to the old behavior up to 3.5.
* - In Scala 3.6 and Scala 3.7-migration, we issue a warning if the result under
* Scala 3.7 differs wrt to the old behavior up to 3.6.
*
* Also and only for given resolution: If a compared type refers to a given or its module class, use
* the intersection of its parent classes instead.
Expand Down
18 changes: 9 additions & 9 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1305,26 +1305,26 @@ trait Implicits:
/** Search a list of eligible implicit references */
private def searchImplicit(eligible: List[Candidate], contextual: Boolean): SearchResult =

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

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

/** Compare `alt1` with `alt2` to determine which one should be chosen.
*
* @return a number > 0 if `alt1` is preferred over `alt2`
* a number < 0 if `alt2` is preferred over `alt1`
* 0 if neither alternative is preferred over the other
* The behavior depends on the source version
* before 3.5: compare with preferGeneral = false
* 3.5: compare twice with preferGeneral = false and true, warning if result is different,
* before 3.6: compare with preferGeneral = false
* 3.6: compare twice with preferGeneral = false and true, warning if result is different,
* return old result with preferGeneral = false
* 3.6-migration: compare twice with preferGeneral = false and true, warning if result is different,
* 3.7-migration: compare twice with preferGeneral = false and true, warning if result is different,
* return new result with preferGeneral = true
* 3.6 and higher: compare with preferGeneral = true
* 3.7 and higher: compare with preferGeneral = true
*
* @param disambiguate The call is used to disambiguate two successes, not for ranking.
* When ranking, we are always filtering out either > 0 or <= 0 results.
Expand All @@ -1348,15 +1348,15 @@ trait Implicits:
case -1 => "the second alternative"
case 1 => "the first alternative"
case _ => "none - it's ambiguous"
if sv.stable == SourceVersion.`3.5` then
if sv.stable == SourceVersion.`3.6` then
warn(
em"""Given search preference for $pt between alternatives
| ${alt1.ref}
|and
| ${alt2.ref}
|will change.
|Current choice : ${choice(prev)}
|New choice from Scala 3.6: ${choice(cmp)}""")
|New choice from Scala 3.7: ${choice(cmp)}""")
prev
else
warn(
Expand All @@ -1366,7 +1366,7 @@ trait Implicits:
| ${alt2.ref}
|has changed.
|Previous choice : ${choice(prev)}
|New choice from Scala 3.6: ${choice(cmp)}""")
|New choice from Scala 3.7: ${choice(cmp)}""")
cmp
else cmp max prev
// When ranking, we keep the better of cmp and prev, which ends up retaining a candidate
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/ctx-bounds-priority.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//> using options -source 3.6
//> using options -source 3.7
trait Eq[A]
trait Order[A] extends Eq[A]:
def toOrdering: Ordering[A]
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/given-triangle.check
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
| (given_B : B)
|will change.
|Current choice : the second alternative
|New choice from Scala 3.6: the first alternative
|New choice from Scala 3.7: the first alternative
2 changes: 1 addition & 1 deletion tests/neg/given-triangle.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//> using options -source 3.5
//> using options -source 3.6
class A
class B extends A
class C extends A
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i15264.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import language.`3.6`
import language.`3.7`
object priority:
// lower number = higher priority
class Prio0 extends Prio1
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i21212.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

//> using options -source 3.7
object Minimization:

trait A
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i21303/Test.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//> using options -source 3.6-migration
//> using options -source 3.7-migration
import scala.deriving.Mirror
import scala.compiletime.*
import scala.reflect.ClassTag
Expand Down
2 changes: 1 addition & 1 deletion tests/run/given-triangle.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import language.`3.6`
import language.`3.7`

class A
class B extends A
Expand Down
2 changes: 1 addition & 1 deletion tests/run/implicit-specifity.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import language.`3.6`
import language.`3.7`

case class Show[T](val i: Int)
object Show {
Expand Down
2 changes: 1 addition & 1 deletion tests/run/implied-priority.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* These tests show various mechanisms available for implicit prioritization.
*/
import language.`3.6`
import language.`3.7`

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

Expand Down
2 changes: 1 addition & 1 deletion tests/warn/i20420.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//> using options -source 3.5-migration
//> using options -source 3.6-migration

final class StrictEqual[V]
final class Less[V]
Expand Down
2 changes: 1 addition & 1 deletion tests/warn/i21036a.check
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
| (a : A)
| will change.
| Current choice : the first alternative
| New choice from Scala 3.6: the second alternative
| New choice from Scala 3.7: the second alternative
2 changes: 1 addition & 1 deletion tests/warn/i21036a.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//> using options -source 3.5
//> using options -source 3.6
trait A
trait B extends A
given b: B = ???
Expand Down
2 changes: 1 addition & 1 deletion tests/warn/i21036b.check
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
| (a : A)
| has changed.
| Previous choice : the first alternative
| New choice from Scala 3.6: the second alternative
| New choice from Scala 3.7: the second alternative
2 changes: 1 addition & 1 deletion tests/warn/i21036b.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//> using options -source 3.6-migration
//> using options -source 3.7-migration
trait A
trait B extends A
given b: B = ???
Expand Down

0 comments on commit 6b1f49f

Please sign in to comment.