Skip to content

Commit f96b298

Browse files
Merge pull request #11619 from dotty-staging/fix-11567
Tighten requirements for migration mode
2 parents b1c5f0b + a156cbe commit f96b298

File tree

7 files changed

+47
-23
lines changed

7 files changed

+47
-23
lines changed

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,7 @@ object Parsers {
17671767
} :: contextBounds(pname)
17681768
case VIEWBOUND =>
17691769
report.errorOrMigrationWarning(
1770-
"view bounds `<%' are deprecated, use a context bound `:' instead",
1770+
"view bounds `<%' are no longer supported, use a context bound `:' instead",
17711771
in.sourcePos())
17721772
atSpan(in.skipToken()) {
17731773
Function(Ident(pname) :: Nil, toplevelTyp())
@@ -2027,10 +2027,10 @@ object Parsers {
20272027
val isVarargSplice = location.inArgs && followingIsVararg()
20282028
in.nextToken()
20292029
if isVarargSplice then
2030-
if sourceVersion.isAtLeast(future) then
2031-
report.errorOrMigrationWarning(
2032-
em"The syntax `x: _*` is no longer supported for vararg splices; use `x*` instead${rewriteNotice("future")}",
2033-
in.sourcePos(uscoreStart))
2030+
report.errorOrMigrationWarning(
2031+
em"The syntax `x: _*` is no longer supported for vararg splices; use `x*` instead${rewriteNotice("future")}",
2032+
in.sourcePos(uscoreStart),
2033+
future)
20342034
if sourceVersion == `future-migration` then
20352035
patch(source, Span(t.span.end, in.lastOffset), " *")
20362036
else if opStack.nonEmpty then
@@ -2103,12 +2103,10 @@ object Parsers {
21032103
val name = bindingName()
21042104
val t =
21052105
if (in.token == COLON && location == Location.InBlock) {
2106-
if sourceVersion.isAtLeast(future) then
2107-
// Don't error in non-strict mode, as the alternative syntax "implicit (x: T) => ... "
2108-
// is not supported by Scala2.x
2109-
report.errorOrMigrationWarning(
2110-
s"This syntax is no longer supported; parameter needs to be enclosed in (...)${rewriteNotice("future")}",
2111-
source.atSpan(Span(start, in.lastOffset)))
2106+
report.errorOrMigrationWarning(
2107+
s"This syntax is no longer supported; parameter needs to be enclosed in (...)${rewriteNotice("future")}",
2108+
source.atSpan(Span(start, in.lastOffset)),
2109+
from = future)
21122110
in.nextToken()
21132111
val t = infixType()
21142112
if (sourceVersion == `future-migration`) {
@@ -2603,10 +2601,10 @@ object Parsers {
26032601
p
26042602

26052603
private def warnStarMigration(p: Tree) =
2606-
if sourceVersion.isAtLeast(future) then
2607-
report.errorOrMigrationWarning(
2608-
em"The syntax `x: _*` is no longer supported for vararg splices; use `x*` instead",
2609-
in.sourcePos(startOffset(p)))
2604+
report.errorOrMigrationWarning(
2605+
em"The syntax `x: _*` is no longer supported for vararg splices; use `x*` instead",
2606+
in.sourcePos(startOffset(p)),
2607+
from = future)
26102608

26112609
/** InfixPattern ::= SimplePattern {id [nl] SimplePattern}
26122610
*/
@@ -3064,7 +3062,8 @@ object Parsers {
30643062
if in.token == USCORE && sourceVersion.isAtLeast(future) then
30653063
report.errorOrMigrationWarning(
30663064
em"`_` is no longer supported for a wildcard import; use `*` instead${rewriteNotice("future")}",
3067-
in.sourcePos())
3065+
in.sourcePos(),
3066+
from = future)
30683067
patch(source, Span(in.offset, in.offset + 1), "*")
30693068
ImportSelector(atSpan(in.skipToken()) { Ident(nme.WILDCARD) })
30703069

@@ -3082,7 +3081,8 @@ object Parsers {
30823081
if in.token == ARROW && sourceVersion.isAtLeast(future) then
30833082
report.errorOrMigrationWarning(
30843083
em"The import renaming `a => b` is no longer supported ; use `a as b` instead${rewriteNotice("future")}",
3085-
in.sourcePos())
3084+
in.sourcePos(),
3085+
from = future)
30863086
patch(source, Span(in.offset, in.offset + 2),
30873087
if testChar(in.offset - 1, ' ') && testChar(in.offset + 2, ' ') then "as"
30883088
else " as ")

compiler/src/dotty/tools/dotc/report.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ object report:
7878
def errorOrMigrationWarning(msg: Message, pos: SrcPos = NoSourcePosition,
7979
from: SourceVersion = SourceVersion.defaultSourceVersion)(using Context): Unit =
8080
if sourceVersion.isAtLeast(from) then
81-
if sourceVersion.isMigrating then migrationWarning(msg, pos)
81+
if sourceVersion.isMigrating && sourceVersion.ordinal <= from.ordinal then migrationWarning(msg, pos)
8282
else error(msg, pos)
8383

8484
def restrictionError(msg: Message, pos: SrcPos = NoSourcePosition)(using Context): Unit =

compiler/src/dotty/tools/dotc/transform/NonLocalReturns.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ class NonLocalReturns extends MiniPhase {
8989

9090
override def transformReturn(tree: Return)(using Context): Tree =
9191
if isNonLocalReturn(tree) then
92-
if sourceVersion.isAtLeast(future) then
93-
report.errorOrMigrationWarning("Non local returns are no longer supported; use scala.util.control.NonLocalReturns instead", tree.srcPos)
92+
report.errorOrMigrationWarning(
93+
"Non local returns are no longer supported; use scala.util.control.NonLocalReturns instead",
94+
tree.srcPos,
95+
from = future)
9496
nonLocalReturnThrow(tree.expr, tree.from.symbol).withSpan(tree.span)
9597
else tree
9698
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,8 +2472,11 @@ class Typer extends Namer
24722472
def remedy =
24732473
if ((prefix ++ suffix).isEmpty) "simply leave out the trailing ` _`"
24742474
else s"use `$prefix<function>$suffix` instead"
2475-
report.errorOrMigrationWarning(i"""The syntax `<function> _` is no longer supported;
2476-
|you can $remedy""", tree.srcPos, future)
2475+
report.errorOrMigrationWarning(
2476+
i"""The syntax `<function> _` is no longer supported;
2477+
|you can $remedy""",
2478+
tree.srcPos,
2479+
from = future)
24772480
if sourceVersion.isMigrating then
24782481
patch(Span(tree.span.start), prefix)
24792482
patch(Span(qual.span.end, tree.span.end), suffix)

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ class CompilationTests {
167167
compileFile("tests/neg-custom-args/i5498-postfixOps.scala", defaultOptions withoutLanguageFeature "postfixOps"),
168168
compileFile("tests/neg-custom-args/deptypes.scala", defaultOptions.and("-language:experimental.dependent")),
169169
compileFile("tests/neg-custom-args/matchable.scala", defaultOptions.and("-Xfatal-warnings", "-source", "future")),
170-
compileFile("tests/neg-custom-args/i7314.scala", defaultOptions.and("-Xfatal-warnings", "-source", "future"))
170+
compileFile("tests/neg-custom-args/i7314.scala", defaultOptions.and("-Xfatal-warnings", "-source", "future")),
171+
compileFile("tests/neg-custom-args/feature-shadowing.scala", defaultOptions.and("-Xfatal-warnings", "-feature")),
171172
).checkExpectedErrors()
172173
}
173174

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import language.implicitConversions
2+
given Conversion[Int, String] = _.toString
3+
4+
object a:
5+
val s: String = 1 // OK
6+
7+
object b:
8+
import language.implicitConversions as _
9+
val s: String = 2 // error
10+
11+
object c:
12+
import language.implicitConversions
13+
val s: String = 3 // OK again

tests/neg/i11567.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import language.`future-migration`
2+
class Test
3+
object Test {
4+
def foo[A <% Test](x: A) = x // error
5+
}

0 commit comments

Comments
 (0)