Skip to content

Commit 9333536

Browse files
Future migration warning for alphanumeric infix operator (#18908)
Copy of #18835 with a clean branch name.
2 parents 41279ac + c79b8e8 commit 9333536

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
@@ -1081,21 +1081,21 @@ trait Checking {
10811081
!name.isOperatorName &&
10821082
!meth.isDeclaredInfix &&
10831083
!meth.maybeOwner.is(Scala2x) &&
1084-
!infixOKSinceFollowedBy(tree.right) &&
1085-
sourceVersion.isAtLeast(future) =>
1084+
!infixOKSinceFollowedBy(tree.right) =>
10861085
val (kind, alternative) =
10871086
if (ctx.mode.is(Mode.Type))
10881087
("type", (n: Name) => s"prefix syntax $n[...]")
10891088
else if (ctx.mode.is(Mode.Pattern))
10901089
("extractor", (n: Name) => s"prefix syntax $n(...)")
10911090
else
10921091
("method", (n: Name) => s"method syntax .$n(...)")
1093-
def rewriteMsg = Message.rewriteNotice("The latter", options = "-deprecation")
1094-
report.deprecationWarning(
1092+
def rewriteMsg = Message.rewriteNotice("The latter", version = `future-migration`)
1093+
report.errorOrMigrationWarning(
10951094
em"""Alphanumeric $kind $name is not declared ${hlAsKeyword("infix")}; it should not be used as infix operator.
10961095
|Instead, use ${alternative(name)} or backticked identifier `$name`.$rewriteMsg""",
1097-
tree.op.srcPos)
1098-
if (ctx.settings.deprecation.value) {
1096+
tree.op.srcPos,
1097+
from = future)
1098+
if sourceVersion == `future-migration` then {
10991099
patch(Span(tree.op.span.start, tree.op.span.start), "`")
11001100
patch(Span(tree.op.span.end, tree.op.span.end), "`")
11011101
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class CompilationTests {
6363
compileFile("tests/rewrites/uninitialized-var.scala", defaultOptions.and("-rewrite", "-source", "future-migration")),
6464
compileFile("tests/rewrites/with-type-operator.scala", defaultOptions.and("-rewrite", "-source", "future-migration")),
6565
compileFile("tests/rewrites/private-this.scala", defaultOptions.and("-rewrite", "-source", "future-migration")),
66+
compileFile("tests/rewrites/alphanumeric-infix-operator.scala", defaultOptions.and("-rewrite", "-source", "future-migration")),
6667
compileFile("tests/rewrites/filtering-fors.scala", defaultOptions.and("-rewrite", "-source", "3.2-migration")),
6768
compileFile("tests/rewrites/refutable-pattern-bindings.scala", defaultOptions.and("-rewrite", "-source", "3.2-migration")),
6869
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)