Skip to content

Commit

Permalink
Rename mode bit
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Jan 5, 2024
1 parent d81746c commit 0852d03
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
13 changes: 8 additions & 5 deletions compiler/src/dotty/tools/dotc/core/Mode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,19 @@ object Mode {
*/
val CheckBoundsOrSelfType: Mode = newMode(14, "CheckBoundsOrSelfType")

/** Use Scala2 scheme for overloading and implicit resolution */
val OldOverloadingResolution: Mode = newMode(15, "OldOverloadingResolution")
/** Use previous Scheme for implicit resolution. Currently significant
* in 3.0-migration where we use Scala-2's scheme instead and in 3.5-migration
* where we use the previous scheme up to 3.4 instead.
*/
val OldImplicitResolution: Mode = newMode(15, "OldImplicitResolution")

/** Treat CapturingTypes as plain AnnotatedTypes even in phase CheckCaptures.
* Reuses the value of OldOverloadingResolution to save Mode bits.
* This is OK since OldOverloadingResolution only affects implicit search, which
* Reuses the value of OldImplicitResolution to save Mode bits.
* This is OK since OldImplicitResolution only affects implicit search, which
* is done during phases Typer and Inlinig, and IgnoreCaptures only has an
* effect during phase CheckCaptures.
*/
val IgnoreCaptures = OldOverloadingResolution
val IgnoreCaptures = OldImplicitResolution

/** Allow hk applications of type lambdas to wildcard arguments;
* used for checking that such applications do not normally arise
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1703,7 +1703,7 @@ trait Applications extends Compatibility {
* and mode.
*
* - In Scala 2, `<:p` was the same as `<:`. This behavior is still
* available in 3.0-migration if mode `Mode.OldOverloadingResolution` is turned on as well.
* 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.4, the behavior is as follows: `T <:p U` iff there is an impliit conversion
Expand All @@ -1727,14 +1727,14 @@ trait Applications extends Compatibility {
* (when `preferGeneral` is true). For old-style implicit values, the 3.4 behavior is kept.
*
* - In Scala 3.5-migration, use the 3.5 scheme normally, and the 3.4 scheme if
* `Mode.OldOverloadingResolution` is on. This is used to highlight differences in the
* `Mode.OldImplicitResolution` is on. This is used to highlight differences in the
* two resolution schemes.
*
* 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.
*/
def isAsGoodValueType(tp1: Type, tp2: Type)(using Context) =
val oldResolution = ctx.mode.is(Mode.OldOverloadingResolution)
val oldResolution = ctx.mode.is(Mode.OldImplicitResolution)
if !preferGeneral || Feature.migrateTo3 && oldResolution then
// Normal specificity test for overloading resolution (where `preferGeneral` is false)
// and in mode Scala3-migration when we compare with the old Scala 2 rules.
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1104,8 +1104,8 @@ trait Implicits:
case result: SearchFailure if result.isAmbiguous =>
val deepPt = pt.deepenProto
if (deepPt ne pt) inferImplicit(deepPt, argument, span)
else if (migrateTo3 && !ctx.mode.is(Mode.OldOverloadingResolution))
withMode(Mode.OldOverloadingResolution)(inferImplicit(pt, argument, span)) match {
else if (migrateTo3 && !ctx.mode.is(Mode.OldImplicitResolution))
withMode(Mode.OldImplicitResolution)(inferImplicit(pt, argument, span)) match {
case altResult: SearchSuccess =>
report.migrationWarning(
result.reason.msg
Expand Down Expand Up @@ -1295,7 +1295,7 @@ trait Implicits:
else
val cmp = comp(using searchContext())
if Feature.sourceVersion == SourceVersion.`3.5-migration` then
val prev = comp(using searchContext().addMode(Mode.OldOverloadingResolution))
val prev = comp(using searchContext().addMode(Mode.OldImplicitResolution))
if cmp != prev then
def choice(c: Int) = c match
case -1 => "the second alternative"
Expand Down

0 comments on commit 0852d03

Please sign in to comment.