Skip to content

Commit bd2dc3e

Browse files
committed
Future migration warning for alphanumeric infix operator
1 parent dc012c3 commit bd2dc3e

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,21 +1075,21 @@ trait Checking {
10751075
!name.isOperatorName &&
10761076
!meth.isDeclaredInfix &&
10771077
!meth.maybeOwner.is(Scala2x) &&
1078-
!infixOKSinceFollowedBy(tree.right) &&
1079-
sourceVersion.isAtLeast(future) =>
1078+
!infixOKSinceFollowedBy(tree.right) =>
10801079
val (kind, alternative) =
10811080
if (ctx.mode.is(Mode.Type))
10821081
("type", (n: Name) => s"prefix syntax $n[...]")
10831082
else if (ctx.mode.is(Mode.Pattern))
10841083
("extractor", (n: Name) => s"prefix syntax $n(...)")
10851084
else
10861085
("method", (n: Name) => s"method syntax .$n(...)")
1087-
def rewriteMsg = Message.rewriteNotice("The latter", options = "-deprecation")
1088-
report.deprecationWarning(
1086+
def rewriteMsg = Message.rewriteNotice("The latter", version = `future-migration`)
1087+
report.errorOrMigrationWarning(
10891088
em"""Alphanumeric $kind $name is not declared ${hlAsKeyword("infix")}; it should not be used as infix operator.
10901089
|Instead, use ${alternative(name)} or backticked identifier `$name`.$rewriteMsg""",
1091-
tree.op.srcPos)
1092-
if (ctx.settings.deprecation.value) {
1090+
tree.op.srcPos,
1091+
from = future)
1092+
if sourceVersion == `future-migration` then {
10931093
patch(Span(tree.op.span.start, tree.op.span.start), "`")
10941094
patch(Span(tree.op.span.end, tree.op.span.end), "`")
10951095
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class CompilationTests {
6161
compileFile("tests/rewrites/rewrites3x.scala", defaultOptions.and("-rewrite", "-source", "future-migration")),
6262
compileFile("tests/rewrites/rewrites3x-fatal-warnings.scala", defaultOptions.and("-rewrite", "-source", "future-migration", "-Xfatal-warnings")),
6363
compileFile("tests/rewrites/with-type-operator.scala", defaultOptions.and("-rewrite", "-source", "future-migration")),
64+
compileFile("tests/rewrites/alphanumeric-infix-operator.scala", defaultOptions.and("-rewrite", "-source", "future-migration")),
6465
compileFile("tests/rewrites/filtering-fors.scala", defaultOptions.and("-rewrite", "-source", "3.2-migration")),
6566
compileFile("tests/rewrites/refutable-pattern-bindings.scala", defaultOptions.and("-rewrite", "-source", "3.2-migration")),
6667
compileFile("tests/rewrites/i8982.scala", defaultOptions.and("-indent", "-rewrite")),

tests/neg/rewrite-messages.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
| ^^^
99
| Alphanumeric method foo is not declared infix; it should not be used as infix operator.
1010
| Instead, use method syntax .foo(...) or backticked identifier `foo`.
11-
| The latter can be rewritten automatically under -rewrite -deprecation.
11+
| The latter can be rewritten automatically under -rewrite -source future-migration.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extension (x: Int) def foo(y: Int): Int = x + y
2+
3+
def f: Unit = 2 `foo` 4
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extension (x: Int) def foo(y: Int): Int = x + y
2+
3+
def f: Unit = 2 foo 4

0 commit comments

Comments
 (0)