Skip to content

Commit 0c0ecd3

Browse files
Backport "Make sure that patches for 3.0 are also applied in later versions" to LTS (#20762)
Backports #19018 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 2aefe84 + edc59a8 commit 0c0ecd3

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ object Parsers {
455455
report.errorOrMigrationWarning(
456456
em"parentheses are required around the parameter of a lambda${rewriteNotice()}",
457457
in.sourcePos(), from = `3.0`)
458-
if migrateTo3 then
458+
if sourceVersion.isMigrating then
459459
patch(source, t.span.startPos, "(")
460460
patch(source, t.span.endPos, ")")
461461
convertToParam(t, mods) :: Nil
@@ -1305,7 +1305,7 @@ object Parsers {
13051305
|For now, you can also `import language.deprecated.symbolLiterals` to accept
13061306
|the idiom, but this possibility might no longer be available in the future.""",
13071307
in.sourcePos(), from = `3.0`)
1308-
if migrateTo3 then
1308+
if sourceVersion.isMigrating then
13091309
patch(source, Span(in.offset, in.offset + 1), "Symbol(\"")
13101310
patch(source, Span(in.charOffset - 1), "\")")
13111311
atSpan(in.skipToken()) { SymbolLit(in.strVal) }
@@ -1403,7 +1403,8 @@ object Parsers {
14031403
|It needs to be indented to the right to keep being treated as
14041404
|an argument to the previous expression.${rewriteNotice()}""",
14051405
in.sourcePos(), from = `3.0`)
1406-
patch(source, Span(in.offset), " ")
1406+
if sourceVersion.isMigrating then
1407+
patch(source, Span(in.offset), " ")
14071408

14081409
def possibleTemplateStart(isNew: Boolean = false): Unit =
14091410
in.observeColonEOL(inTemplate = true)
@@ -2222,7 +2223,7 @@ object Parsers {
22222223
val whileStart = in.offset
22232224
accept(WHILE)
22242225
val cond = expr()
2225-
if migrateTo3 then
2226+
if sourceVersion.isMigrating then
22262227
patch(source, Span(start, start + 2), "while ({")
22272228
patch(source, Span(whileStart, whileStart + 5), ";")
22282229
cond match {

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
@@ -441,7 +441,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
441441
report.errorOrMigrationWarning(
442442
AmbiguousReference(name, Definition, Inheritance, prevCtx)(using outer),
443443
pos, from = `3.0`)
444-
if migrateTo3 then
444+
if sourceVersion.isMigrating then
445445
patch(Span(pos.span.start),
446446
if prevCtx.owner == refctx.owner.enclosingClass then "this."
447447
else s"${prevCtx.owner.name}.this.")
@@ -2892,13 +2892,12 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
28922892
val recovered = typed(qual)(using ctx.fresh.setExploreTyperState())
28932893
val msg = OnlyFunctionsCanBeFollowedByUnderscore(recovered.tpe.widen, tree)
28942894
report.errorOrMigrationWarning(msg, tree.srcPos, from = `3.0`)
2895-
if (migrateTo3) {
2895+
if sourceVersion.isMigrating then
28962896
// Under -rewrite, patch `x _` to `(() => x)`
28972897
msg.actions
28982898
.headOption
28992899
.foreach(Rewrites.applyAction)
29002900
return typed(untpd.Function(Nil, qual), pt)
2901-
}
29022901
}
29032902
nestedCtx.typerState.commit()
29042903
if sourceVersion.isAtLeast(future) then

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)