diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 5fd1e165cf20..21bf0bc81cd0 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -1081,8 +1081,7 @@ trait Checking { !name.isOperatorName && !meth.isDeclaredInfix && !meth.maybeOwner.is(Scala2x) && - !infixOKSinceFollowedBy(tree.right) && - sourceVersion.isAtLeast(future) => + !infixOKSinceFollowedBy(tree.right) => val (kind, alternative) = if (ctx.mode.is(Mode.Type)) ("type", (n: Name) => s"prefix syntax $n[...]") @@ -1090,12 +1089,13 @@ trait Checking { ("extractor", (n: Name) => s"prefix syntax $n(...)") else ("method", (n: Name) => s"method syntax .$n(...)") - def rewriteMsg = Message.rewriteNotice("The latter", options = "-deprecation") - report.deprecationWarning( + def rewriteMsg = Message.rewriteNotice("The latter", version = `future-migration`) + report.errorOrMigrationWarning( em"""Alphanumeric $kind $name is not declared ${hlAsKeyword("infix")}; it should not be used as infix operator. |Instead, use ${alternative(name)} or backticked identifier `$name`.$rewriteMsg""", - tree.op.srcPos) - if (ctx.settings.deprecation.value) { + tree.op.srcPos, + from = future) + if sourceVersion == `future-migration` then { patch(Span(tree.op.span.start, tree.op.span.start), "`") patch(Span(tree.op.span.end, tree.op.span.end), "`") } diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 21235ac048e2..9a305a926a9c 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -63,6 +63,7 @@ class CompilationTests { compileFile("tests/rewrites/uninitialized-var.scala", defaultOptions.and("-rewrite", "-source", "future-migration")), compileFile("tests/rewrites/with-type-operator.scala", defaultOptions.and("-rewrite", "-source", "future-migration")), compileFile("tests/rewrites/private-this.scala", defaultOptions.and("-rewrite", "-source", "future-migration")), + compileFile("tests/rewrites/alphanumeric-infix-operator.scala", defaultOptions.and("-rewrite", "-source", "future-migration")), compileFile("tests/rewrites/filtering-fors.scala", defaultOptions.and("-rewrite", "-source", "3.2-migration")), compileFile("tests/rewrites/refutable-pattern-bindings.scala", defaultOptions.and("-rewrite", "-source", "3.2-migration")), compileFile("tests/rewrites/i8982.scala", defaultOptions.and("-indent", "-rewrite")), diff --git a/tests/neg/rewrite-messages.check b/tests/neg/rewrite-messages.check index 3ee081edbed2..f368c2dc8997 100644 --- a/tests/neg/rewrite-messages.check +++ b/tests/neg/rewrite-messages.check @@ -8,4 +8,4 @@ | ^^^ | Alphanumeric method foo is not declared infix; it should not be used as infix operator. | Instead, use method syntax .foo(...) or backticked identifier `foo`. - | The latter can be rewritten automatically under -rewrite -deprecation. + | The latter can be rewritten automatically under -rewrite -source future-migration. diff --git a/tests/rewrites/alphanumeric-infix-operator.check b/tests/rewrites/alphanumeric-infix-operator.check new file mode 100644 index 000000000000..8ff077e856cf --- /dev/null +++ b/tests/rewrites/alphanumeric-infix-operator.check @@ -0,0 +1,3 @@ +extension (x: Int) def foo(y: Int): Int = x + y + +def f: Unit = 2 `foo` 4 diff --git a/tests/rewrites/alphanumeric-infix-operator.scala b/tests/rewrites/alphanumeric-infix-operator.scala new file mode 100644 index 000000000000..450f44834f05 --- /dev/null +++ b/tests/rewrites/alphanumeric-infix-operator.scala @@ -0,0 +1,3 @@ +extension (x: Int) def foo(y: Int): Int = x + y + +def f: Unit = 2 foo 4