Skip to content

Commit ff6f50a

Browse files
authored
Refactor config.MigrationVersion (#21399)
This PR refactors `config.MigrationVersion` to be an enum. This is not only correct to have it as an enum but it is also easier to read the code with this change.
2 parents b583664 + a818608 commit ff6f50a

File tree

1 file changed

+25
-37
lines changed

1 file changed

+25
-37
lines changed

compiler/src/dotty/tools/dotc/config/MigrationVersion.scala

+25-37
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,36 @@ import SourceVersion.*
66
import Feature.*
77
import core.Contexts.Context
88

9-
class MigrationVersion(
10-
val warnFrom: SourceVersion,
11-
val errorFrom: SourceVersion):
12-
require(warnFrom.ordinal <= errorFrom.ordinal)
13-
14-
def needsPatch(using Context): Boolean =
15-
sourceVersion.isMigrating && sourceVersion.isAtLeast(warnFrom)
16-
17-
def patchFrom: SourceVersion =
18-
warnFrom.prevMigrating
19-
20-
object MigrationVersion:
21-
22-
val Scala2to3 = MigrationVersion(`3.0`, `3.0`)
23-
24-
val OverrideValParameter = MigrationVersion(`3.0`, future)
25-
9+
enum MigrationVersion(val warnFrom: SourceVersion, val errorFrom: SourceVersion):
10+
case Scala2to3 extends MigrationVersion(`3.0`, `3.0`)
11+
case OverrideValParameter extends MigrationVersion(`3.0`, future)
2612
// we tighten for-comprehension without `case` to error in 3.4,
2713
// but we keep pat-defs as warnings for now ("@unchecked"),
2814
// until we propose an alternative way to assert exhaustivity to the typechecker.
29-
val ForComprehensionPatternWithoutCase = MigrationVersion(`3.2`, `3.4`)
30-
val ForComprehensionUncheckedPathDefs = MigrationVersion(`3.2`, future)
31-
32-
val NonLocalReturns = MigrationVersion(`3.2`, future)
33-
34-
val AscriptionAfterPattern = MigrationVersion(`3.3`, future)
35-
36-
val ExplicitContextBoundArgument = MigrationVersion(`3.4`, `3.5`)
15+
case ForComprehensionPatternWithoutCase extends MigrationVersion(`3.2`, `3.4`)
16+
case ForComprehensionUncheckedPathDefs extends MigrationVersion(`3.2`, future)
17+
18+
case NonLocalReturns extends MigrationVersion(`3.2`, future)
19+
case AscriptionAfterPattern extends MigrationVersion(`3.3`, future)
20+
case ExplicitContextBoundArgument extends MigrationVersion(`3.4`, `3.5`)
21+
case AlphanumericInfix extends MigrationVersion(`3.4`, future)
22+
case RemoveThisQualifier extends MigrationVersion(`3.4`, future)
23+
case UninitializedVars extends MigrationVersion(`3.4`, future)
24+
case VarargSpliceAscription extends MigrationVersion(`3.4`, future)
25+
case WildcardType extends MigrationVersion(`3.4`, future)
26+
case WithOperator extends MigrationVersion(`3.4`, future)
27+
case FunctionUnderscore extends MigrationVersion(`3.4`, future)
28+
case NonNamedArgumentInJavaAnnotation extends MigrationVersion(`3.6`, `3.6`)
29+
case ImportWildcard extends MigrationVersion(future, future)
30+
case ImportRename extends MigrationVersion(future, future)
31+
case ParameterEnclosedByParenthesis extends MigrationVersion(future, future)
32+
case XmlLiteral extends MigrationVersion(future, future)
3733

38-
val AlphanumericInfix = MigrationVersion(`3.4`, future)
39-
val RemoveThisQualifier = MigrationVersion(`3.4`, future)
40-
val UninitializedVars = MigrationVersion(`3.4`, future)
41-
val VarargSpliceAscription = MigrationVersion(`3.4`, future)
42-
val WildcardType = MigrationVersion(`3.4`, future)
43-
val WithOperator = MigrationVersion(`3.4`, future)
44-
val FunctionUnderscore = MigrationVersion(`3.4`, future)
34+
require(warnFrom.ordinal <= errorFrom.ordinal)
4535

46-
val NonNamedArgumentInJavaAnnotation = MigrationVersion(`3.6`, `3.6`)
36+
def needsPatch(using Context): Boolean =
37+
sourceVersion.isMigrating && sourceVersion.isAtLeast(warnFrom)
4738

48-
val ImportWildcard = MigrationVersion(future, future)
49-
val ImportRename = MigrationVersion(future, future)
50-
val ParameterEnclosedByParenthesis = MigrationVersion(future, future)
51-
val XmlLiteral = MigrationVersion(future, future)
39+
def patchFrom: SourceVersion = warnFrom.prevMigrating
5240

5341
end MigrationVersion

0 commit comments

Comments
 (0)