@@ -33,6 +33,7 @@ import config.Feature
33
33
import config .Feature .{sourceVersion , migrateTo3 , globalOnlyImports }
34
34
import config .SourceVersion .*
35
35
import config .SourceVersion
36
+ import dotty .tools .dotc .config .MigrationVersion
36
37
37
38
object Parsers {
38
39
@@ -462,8 +463,8 @@ object Parsers {
462
463
case t @ Typed (Ident (_), _) =>
463
464
report.errorOrMigrationWarning(
464
465
em " parentheses are required around the parameter of a lambda ${rewriteNotice()}" ,
465
- in.sourcePos(), from = `3.0` )
466
- if sourceVersion.isMigrating then
466
+ in.sourcePos(), MigrationVersion . Scala2to3 )
467
+ if MigrationVersion . Scala2to3 .needsPatch then
467
468
patch(source, t.span.startPos, " (" )
468
469
patch(source, t.span.endPos, " )" )
469
470
convertToParam(t, mods) :: Nil
@@ -1314,8 +1315,8 @@ object Parsers {
1314
1315
|or enclose in braces '{ $name} if you want a quoted expression.
1315
1316
|For now, you can also `import language.deprecated.symbolLiterals` to accept
1316
1317
|the idiom, but this possibility might no longer be available in the future. """ ,
1317
- in.sourcePos(), from = `3.0` )
1318
- if sourceVersion.isMigrating then
1318
+ in.sourcePos(), MigrationVersion . Scala2to3 )
1319
+ if MigrationVersion . Scala2to3 .needsPatch then
1319
1320
patch(source, Span (in.offset, in.offset + 1 ), " Symbol(\" " )
1320
1321
patch(source, Span (in.charOffset - 1 ), " \" )" )
1321
1322
atSpan(in.skipToken()) { SymbolLit (in.strVal) }
@@ -1412,8 +1413,8 @@ object Parsers {
1412
1413
em """ This opening brace will start a new statement in Scala 3.
1413
1414
|It needs to be indented to the right to keep being treated as
1414
1415
|an argument to the previous expression. ${rewriteNotice()}""" ,
1415
- in.sourcePos(), from = `3.0` )
1416
- if sourceVersion.isMigrating then
1416
+ in.sourcePos(), MigrationVersion . Scala2to3 )
1417
+ if MigrationVersion . Scala2to3 .needsPatch then
1417
1418
patch(source, Span (in.offset), " " )
1418
1419
1419
1420
def possibleTemplateStart (isNew : Boolean = false ): Unit =
@@ -1776,12 +1777,11 @@ object Parsers {
1776
1777
t
1777
1778
else
1778
1779
val withSpan = Span (withOffset, withOffset + 4 )
1779
- report.gradualErrorOrMigrationWarning (
1780
+ report.errorOrMigrationWarning (
1780
1781
DeprecatedWithOperator (rewriteNotice(`3.4-migration`)),
1781
1782
source.atSpan(withSpan),
1782
- warnFrom = `3.4`,
1783
- errorFrom = future)
1784
- if sourceVersion.isMigrating && sourceVersion.isAtLeast(`3.4-migration`) then
1783
+ MigrationVersion .WithOperator )
1784
+ if MigrationVersion .WithOperator .needsPatch then
1785
1785
patch(source, withSpan, " &" )
1786
1786
atSpan(startOffset(t)) { makeAndType(t, withType()) }
1787
1787
else t
@@ -1882,12 +1882,11 @@ object Parsers {
1882
1882
Ident (tpnme.USCOREkw ).withSpan(Span (start, in.lastOffset, start))
1883
1883
else
1884
1884
if ! inTypeMatchPattern then
1885
- report.gradualErrorOrMigrationWarning (
1885
+ report.errorOrMigrationWarning (
1886
1886
em " `_` is deprecated for wildcard arguments of types: use `?` instead ${rewriteNotice(`3.4-migration`)}" ,
1887
1887
in.sourcePos(),
1888
- warnFrom = `3.4`,
1889
- errorFrom = future)
1890
- if sourceVersion.isMigrating && sourceVersion.isAtLeast(`3.4-migration`) then
1888
+ MigrationVersion .WildcardType )
1889
+ if MigrationVersion .WildcardType .needsPatch then
1891
1890
patch(source, Span (in.offset, in.offset + 1 ), " ?" )
1892
1891
end if
1893
1892
val start = in.skipToken()
@@ -2111,7 +2110,7 @@ object Parsers {
2111
2110
else if in.token == VIEWBOUND then
2112
2111
report.errorOrMigrationWarning(
2113
2112
em " view bounds `<%' are no longer supported, use a context bound `:' instead " ,
2114
- in.sourcePos(), from = `3.0` )
2113
+ in.sourcePos(), MigrationVersion . Scala2to3 )
2115
2114
atSpan(in.skipToken()) {
2116
2115
Function (Ident (pname) :: Nil , toplevelTyp())
2117
2116
} :: contextBounds(pname)
@@ -2260,15 +2259,15 @@ object Parsers {
2260
2259
report.errorOrMigrationWarning(
2261
2260
em """ `do <body> while <cond>` is no longer supported,
2262
2261
|use `while <body> ; <cond> do ()` instead. ${rewriteNotice()}""" ,
2263
- in.sourcePos(), from = `3.0` )
2262
+ in.sourcePos(), MigrationVersion . Scala2to3 )
2264
2263
val start = in.skipToken()
2265
2264
atSpan(start) {
2266
2265
val body = expr()
2267
2266
if (isStatSep) in.nextToken()
2268
2267
val whileStart = in.offset
2269
2268
accept(WHILE )
2270
2269
val cond = expr()
2271
- if sourceVersion.isMigrating then
2270
+ if MigrationVersion . Scala2to3 .needsPatch then
2272
2271
patch(source, Span (start, start + 2 ), " while ({" )
2273
2272
patch(source, Span (whileStart, whileStart + 5 ), " ;" )
2274
2273
cond match {
@@ -2370,18 +2369,17 @@ object Parsers {
2370
2369
val isVarargSplice = location.inArgs && followingIsVararg()
2371
2370
in.nextToken()
2372
2371
if isVarargSplice then
2373
- report.gradualErrorOrMigrationWarning (
2372
+ report.errorOrMigrationWarning (
2374
2373
em " The syntax `x: _*` is no longer supported for vararg splices; use `x*` instead ${rewriteNotice(`3.4-migration`)}" ,
2375
2374
in.sourcePos(uscoreStart),
2376
- warnFrom = `3.4`,
2377
- errorFrom = future)
2378
- if sourceVersion.isMigrating && sourceVersion.isAtLeast(`3.4-migration`) then
2375
+ MigrationVersion .VarargSpliceAscription )
2376
+ if MigrationVersion .VarargSpliceAscription .needsPatch then
2379
2377
patch(source, Span (t.span.end, in.lastOffset), " *" )
2380
2378
else if opStack.nonEmpty then
2381
2379
report.errorOrMigrationWarning(
2382
2380
em """ `_*` can be used only for last argument of method application.
2383
2381
|It is no longer allowed in operands of infix operations. """ ,
2384
- in.sourcePos(uscoreStart), from = `3.0` )
2382
+ in.sourcePos(uscoreStart), MigrationVersion . Scala2to3 )
2385
2383
else
2386
2384
syntaxError(SeqWildcardPatternPos (), uscoreStart)
2387
2385
Typed (t, atSpan(uscoreStart) { Ident (tpnme.WILDCARD_STAR ) })
@@ -2448,13 +2446,12 @@ object Parsers {
2448
2446
report.errorOrMigrationWarning(
2449
2447
em " This syntax is no longer supported; parameter needs to be enclosed in (...) ${rewriteNotice(`future-migration`)}" ,
2450
2448
source.atSpan(Span (start, in.lastOffset)),
2451
- from = future )
2449
+ MigrationVersion . ParameterEnclosedByParenthesis )
2452
2450
in.nextToken()
2453
2451
val t = infixType()
2454
- if (sourceVersion == `future-migration`) {
2452
+ if MigrationVersion . ParameterEnclosedByParenthesis .needsPatch then
2455
2453
patch(source, Span (start), " (" )
2456
2454
patch(source, Span (in.lastOffset), " )" )
2457
- }
2458
2455
t
2459
2456
}
2460
2457
else TypeTree ()
@@ -2958,15 +2955,13 @@ object Parsers {
2958
2955
if in.isColon then
2959
2956
val isVariableOrNumber = isVarPattern(p) || p.isInstanceOf [Number ]
2960
2957
if ! isVariableOrNumber then
2961
- report.gradualErrorOrMigrationWarning (
2958
+ report.errorOrMigrationWarning (
2962
2959
em """ Type ascriptions after patterns other than:
2963
2960
| * variable pattern, e.g. `case x: String =>`
2964
2961
| * number literal pattern, e.g. `case 10.5: Double =>`
2965
2962
|are no longer supported. Remove the type ascription or move it to a separate variable pattern. """ ,
2966
2963
in.sourcePos(),
2967
- warnFrom = `3.3`,
2968
- errorFrom = future
2969
- )
2964
+ MigrationVersion .AscriptionAfterPattern )
2970
2965
in.nextToken()
2971
2966
ascription(p, location)
2972
2967
else p
@@ -3147,13 +3142,12 @@ object Parsers {
3147
3142
else mods.withPrivateWithin(ident().toTypeName)
3148
3143
}
3149
3144
if mods1.is(Local ) then
3150
- report.gradualErrorOrMigrationWarning (
3145
+ report.errorOrMigrationWarning (
3151
3146
em """ The [this] qualifier will be deprecated in the future; it should be dropped.
3152
3147
|See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html ${rewriteNotice(`3.4-migration`)}""" ,
3153
3148
in.sourcePos(),
3154
- warnFrom = `3.4`,
3155
- errorFrom = future)
3156
- if sourceVersion.isMigrating && sourceVersion.isAtLeast(`3.4-migration`) then
3149
+ MigrationVersion .RemoveThisQualifier )
3150
+ if MigrationVersion .RemoveThisQualifier .needsPatch then
3157
3151
patch(source, Span (startOffset, in.lastOffset), " " )
3158
3152
mods1
3159
3153
}
@@ -3542,8 +3536,8 @@ object Parsers {
3542
3536
report.errorOrMigrationWarning(
3543
3537
em " `_` is no longer supported for a wildcard $exprName; use `*` instead ${rewriteNotice(`future-migration`)}" ,
3544
3538
in.sourcePos(),
3545
- from = future )
3546
- if sourceVersion == `future-migration` then
3539
+ MigrationVersion . ImportWildcard )
3540
+ if MigrationVersion . ImportWildcard .needsPatch then
3547
3541
patch(source, Span (in.offset, in.offset + 1 ), " *" )
3548
3542
ImportSelector (atSpan(in.skipToken()) { Ident (nme.WILDCARD ) })
3549
3543
@@ -3562,8 +3556,8 @@ object Parsers {
3562
3556
report.errorOrMigrationWarning(
3563
3557
em " The $exprName renaming `a => b` is no longer supported ; use `a as b` instead ${rewriteNotice(`future-migration`)}" ,
3564
3558
in.sourcePos(),
3565
- from = future )
3566
- if sourceVersion == `future-migration` then
3559
+ MigrationVersion . ImportRename )
3560
+ if MigrationVersion . ImportRename .needsPatch then
3567
3561
patch(source, Span (in.offset, in.offset + 2 ),
3568
3562
if testChar(in.offset - 1 , ' ' ) && testChar(in.offset + 2 , ' ' ) then " as"
3569
3563
else " as " )
@@ -3674,13 +3668,12 @@ object Parsers {
3674
3668
subExpr() match
3675
3669
case rhs0 @ Ident (name) if placeholderParams.nonEmpty && name == placeholderParams.head.name
3676
3670
&& ! tpt.isEmpty && mods.is(Mutable ) && lhs.forall(_.isInstanceOf [Ident ]) =>
3677
- report.gradualErrorOrMigrationWarning (
3671
+ report.errorOrMigrationWarning (
3678
3672
em """ `= _` has been deprecated; use `= uninitialized` instead.
3679
3673
|`uninitialized` can be imported with `scala.compiletime.uninitialized`. ${rewriteNotice(`3.4-migration`)}""" ,
3680
3674
in.sourcePos(rhsOffset),
3681
- warnFrom = `3.4`,
3682
- errorFrom = future)
3683
- if sourceVersion.isMigrating && sourceVersion.isAtLeast(`3.4-migration`) then
3675
+ MigrationVersion .UninitializedVars )
3676
+ if MigrationVersion .UninitializedVars .needsPatch then
3684
3677
patch(source, Span (rhsOffset, rhsOffset + 1 ), " scala.compiletime.uninitialized" )
3685
3678
placeholderParams = placeholderParams.tail
3686
3679
atSpan(rhs0.span) { Ident (nme.WILDCARD ) }
@@ -3722,9 +3715,10 @@ object Parsers {
3722
3715
else " : Unit " // trailing space ensures that `def f()def g()` works.
3723
3716
if migrateTo3 then
3724
3717
report.errorOrMigrationWarning(
3725
- em " Procedure syntax no longer supported; ` $toInsert` should be inserted here " ,
3726
- in.sourcePos(), from = `3.0`)
3727
- patch(source, Span (in.lastOffset), toInsert)
3718
+ em " Procedure syntax no longer supported; ` $toInsert` should be inserted here ${rewriteNotice()}" ,
3719
+ in.sourcePos(), MigrationVersion .Scala2to3 )
3720
+ if MigrationVersion .Scala2to3 .needsPatch then
3721
+ patch(source, Span (in.lastOffset), toInsert)
3728
3722
true
3729
3723
else
3730
3724
false
@@ -4150,7 +4144,7 @@ object Parsers {
4150
4144
if (in.token == LBRACE || in.token == COLONeol ) {
4151
4145
report.errorOrMigrationWarning(
4152
4146
em " `extends` must be followed by at least one parent " ,
4153
- in.sourcePos(), from = `3.0` )
4147
+ in.sourcePos(), MigrationVersion . Scala2to3 )
4154
4148
Nil
4155
4149
}
4156
4150
else constrApps()
0 commit comments