Skip to content

Commit 1a947f9

Browse files
committed
Cleanup errorOrMigrationWarnings
1 parent 6c019bc commit 1a947f9

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,10 +2084,10 @@ object Parsers {
20842084
val isVarargSplice = location.inArgs && followingIsVararg()
20852085
in.nextToken()
20862086
if isVarargSplice then
2087-
if sourceVersion.isAtLeast(future) then
2088-
report.errorOrMigrationWarning(
2089-
em"The syntax `x: _*` is no longer supported for vararg splices; use `x*` instead${rewriteNotice("future")}",
2090-
in.sourcePos(uscoreStart))
2087+
report.errorOrMigrationWarning(
2088+
em"The syntax `x: _*` is no longer supported for vararg splices; use `x*` instead${rewriteNotice("future")}",
2089+
in.sourcePos(uscoreStart),
2090+
future)
20912091
if sourceVersion == `future-migration` then
20922092
patch(source, Span(t.span.end, in.lastOffset), " *")
20932093
else if opStack.nonEmpty then
@@ -2162,12 +2162,10 @@ object Parsers {
21622162
val name = bindingName()
21632163
val t =
21642164
if (in.token == COLON && location == Location.InBlock) {
2165-
if sourceVersion.isAtLeast(future) then
2166-
// Don't error in non-strict mode, as the alternative syntax "implicit (x: T) => ... "
2167-
// is not supported by Scala2.x
2168-
report.errorOrMigrationWarning(
2169-
s"This syntax is no longer supported; parameter needs to be enclosed in (...)${rewriteNotice("future")}",
2170-
source.atSpan(Span(start, in.lastOffset)))
2165+
report.errorOrMigrationWarning(
2166+
s"This syntax is no longer supported; parameter needs to be enclosed in (...)${rewriteNotice("future")}",
2167+
source.atSpan(Span(start, in.lastOffset)),
2168+
from = future)
21712169
in.nextToken()
21722170
val t = infixType()
21732171
if (sourceVersion == `future-migration`) {
@@ -2665,10 +2663,10 @@ object Parsers {
26652663
p
26662664

26672665
private def warnStarMigration(p: Tree) =
2668-
if sourceVersion.isAtLeast(future) then
2669-
report.errorOrMigrationWarning(
2670-
em"The syntax `x: _*` is no longer supported for vararg splices; use `x*` instead",
2671-
in.sourcePos(startOffset(p)))
2666+
report.errorOrMigrationWarning(
2667+
em"The syntax `x: _*` is no longer supported for vararg splices; use `x*` instead",
2668+
in.sourcePos(startOffset(p)),
2669+
from = future)
26722670

26732671
/** InfixPattern ::= SimplePattern {id [nl] SimplePattern}
26742672
*/
@@ -3124,7 +3122,8 @@ object Parsers {
31243122
if in.token == USCORE && sourceVersion.isAtLeast(future) then
31253123
report.errorOrMigrationWarning(
31263124
em"`_` is no longer supported for a wildcard import; use `*` instead${rewriteNotice("future")}",
3127-
in.sourcePos())
3125+
in.sourcePos(),
3126+
from = future)
31283127
patch(source, Span(in.offset, in.offset + 1), "*")
31293128
ImportSelector(atSpan(in.skipToken()) { Ident(nme.WILDCARD) })
31303129

@@ -3142,7 +3141,8 @@ object Parsers {
31423141
if in.token == ARROW && sourceVersion.isAtLeast(future) then
31433142
report.errorOrMigrationWarning(
31443143
em"The import renaming `a => b` is no longer supported ; use `a as b` instead${rewriteNotice("future")}",
3145-
in.sourcePos())
3144+
in.sourcePos(),
3145+
from = future)
31463146
patch(source, Span(in.offset, in.offset + 2),
31473147
if testChar(in.offset - 1, ' ') && testChar(in.offset + 2, ' ') then "as"
31483148
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.ordinal < from.ordinal 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 =

0 commit comments

Comments
 (0)