Skip to content

Commit c233061

Browse files
Make sure that patches for 3.0 are also applied in later versions (#19018)
2 parents f831830 + 590e159 commit c233061

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ object Parsers {
463463
report.errorOrMigrationWarning(
464464
em"parentheses are required around the parameter of a lambda${rewriteNotice()}",
465465
in.sourcePos(), from = `3.0`)
466-
if migrateTo3 then
466+
if sourceVersion.isMigrating then
467467
patch(source, t.span.startPos, "(")
468468
patch(source, t.span.endPos, ")")
469469
convertToParam(t, mods) :: Nil
@@ -1315,7 +1315,7 @@ object Parsers {
13151315
|For now, you can also `import language.deprecated.symbolLiterals` to accept
13161316
|the idiom, but this possibility might no longer be available in the future.""",
13171317
in.sourcePos(), from = `3.0`)
1318-
if migrateTo3 then
1318+
if sourceVersion.isMigrating then
13191319
patch(source, Span(in.offset, in.offset + 1), "Symbol(\"")
13201320
patch(source, Span(in.charOffset - 1), "\")")
13211321
atSpan(in.skipToken()) { SymbolLit(in.strVal) }
@@ -1413,7 +1413,8 @@ object Parsers {
14131413
|It needs to be indented to the right to keep being treated as
14141414
|an argument to the previous expression.${rewriteNotice()}""",
14151415
in.sourcePos(), from = `3.0`)
1416-
patch(source, Span(in.offset), " ")
1416+
if sourceVersion.isMigrating then
1417+
patch(source, Span(in.offset), " ")
14171418

14181419
def possibleTemplateStart(isNew: Boolean = false): Unit =
14191420
in.observeColonEOL(inTemplate = true)
@@ -2267,7 +2268,7 @@ object Parsers {
22672268
val whileStart = in.offset
22682269
accept(WHILE)
22692270
val cond = expr()
2270-
if migrateTo3 then
2271+
if sourceVersion.isMigrating then
22712272
patch(source, Span(start, start + 2), "while ({")
22722273
patch(source, Span(whileStart, whileStart + 5), ";")
22732274
cond match {
@@ -3153,7 +3154,7 @@ object Parsers {
31533154
warnFrom = `3.4`,
31543155
errorFrom = future)
31553156
if sourceVersion.isMigrating && sourceVersion.isAtLeast(`3.4-migration`) then
3156-
patch(source, Span(startOffset, in.lastOffset), "")
3157+
patch(source, Span(startOffset, in.lastOffset), "")
31573158
mods1
31583159
}
31593160
else mods

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ import scala.collection.immutable.SortedMap
1818
import rewrites.Rewrites.patch
1919
import config.Feature
2020
import config.Feature.{migrateTo3, fewerBracesEnabled}
21-
import config.SourceVersion.`3.0`
21+
import config.SourceVersion.{`3.0`, `3.0-migration`}
2222
import reporting.{NoProfile, Profile, Message}
2323

2424
import java.util.Objects
25+
import dotty.tools.dotc.reporting.Message.rewriteNotice
26+
import dotty.tools.dotc.config.Feature.sourceVersion
2527

2628
object Scanners {
2729

@@ -253,11 +255,12 @@ object Scanners {
253255
if scala3keywords.contains(keyword) && migrateTo3 then
254256
val what = tokenString(keyword)
255257
report.errorOrMigrationWarning(
256-
em"$what is now a keyword, write `$what` instead of $what to keep it as an identifier",
258+
em"$what is now a keyword, write `$what` instead of $what to keep it as an identifier${rewriteNotice("This", `3.0-migration`)}",
257259
sourcePos(),
258260
from = `3.0`)
259-
patch(source, Span(offset), "`")
260-
patch(source, Span(offset + identifier.length), "`")
261+
if sourceVersion.isMigrating then
262+
patch(source, Span(offset), "`")
263+
patch(source, Span(offset + identifier.length), "`")
261264
IDENTIFIER
262265
else keyword
263266
val idx = identifier.start

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
448448
report.errorOrMigrationWarning(
449449
AmbiguousReference(name, Definition, Inheritance, prevCtx)(using outer),
450450
pos, from = `3.0`)
451-
if migrateTo3 then
451+
if sourceVersion.isMigrating then
452452
patch(Span(pos.span.start),
453453
if prevCtx.owner == refctx.owner.enclosingClass then "this."
454454
else s"${prevCtx.owner.name}.this.")
@@ -2984,13 +2984,12 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
29842984
val recovered = typed(qual)(using ctx.fresh.setExploreTyperState())
29852985
val msg = OnlyFunctionsCanBeFollowedByUnderscore(recovered.tpe.widen, tree)
29862986
report.errorOrMigrationWarning(msg, tree.srcPos, from = `3.0`)
2987-
if (migrateTo3) {
2987+
if sourceVersion.isMigrating then
29882988
// Under -rewrite, patch `x _` to `(() => x)`
29892989
msg.actions
29902990
.headOption
29912991
.foreach(Rewrites.applyAction)
29922992
return typed(untpd.Function(Nil, qual), pt)
2993-
}
29942993
}
29952994
nestedCtx.typerState.commit()
29962995

tests/neg/i13440.check

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
5 |def given = 42 // error
33
| ^
44
| given is now a keyword, write `given` instead of given to keep it as an identifier
5+
| This can be rewritten automatically under -rewrite -source 3.0-migration.
56
-- Error: tests/neg/i13440.scala:7:13 ----------------------------------------------------------------------------------
67
7 |case class C(enum: List[Int] = Nil) { // error
78
| ^
89
| enum is now a keyword, write `enum` instead of enum to keep it as an identifier
10+
| This can be rewritten automatically under -rewrite -source 3.0-migration.
911
-- Error: tests/neg/i13440.scala:8:11 ----------------------------------------------------------------------------------
1012
8 | val s = s"$enum" // error
1113
| ^
1214
| enum is now a keyword, write `enum` instead of enum to keep it as an identifier
15+
| This can be rewritten automatically under -rewrite -source 3.0-migration.

0 commit comments

Comments
 (0)