Skip to content

Commit 04215fc

Browse files
committed
Deprecation warnings for old syntax: alphanumeric infix operators
This is the first part of scala#18870
1 parent 312e4bb commit 04215fc

10 files changed

+73
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,7 @@ trait Checking {
10811081
!name.isOperatorName &&
10821082
!meth.isDeclaredInfix &&
10831083
!meth.maybeOwner.is(Scala2x) &&
1084+
// TODO check is meth was compiled with 3.4+ compiler
10841085
!infixOKSinceFollowedBy(tree.right) =>
10851086
val (kind, alternative) =
10861087
if (ctx.mode.is(Mode.Type))
@@ -1089,13 +1090,14 @@ trait Checking {
10891090
("extractor", (n: Name) => s"prefix syntax $n(...)")
10901091
else
10911092
("method", (n: Name) => s"method syntax .$n(...)")
1092-
def rewriteMsg = Message.rewriteNotice("The latter", version = `future-migration`)
1093-
report.errorOrMigrationWarning(
1093+
def rewriteMsg = Message.rewriteNotice("The latter", version = `3.4-migration`)
1094+
report.gradualErrorOrMigrationWarning(
10941095
em"""Alphanumeric $kind $name is not declared ${hlAsKeyword("infix")}; it should not be used as infix operator.
10951096
|Instead, use ${alternative(name)} or backticked identifier `$name`.$rewriteMsg""",
10961097
tree.op.srcPos,
1097-
from = future)
1098-
if sourceVersion == `future-migration` then {
1098+
warnFrom = `3.4`,
1099+
errorFrom = future)
1100+
if sourceVersion.isMigrating && sourceVersion.isAtLeast(`3.4-migration`) then {
10991101
patch(Span(tree.op.span.start, tree.op.span.start), "`")
11001102
patch(Span(tree.op.span.end, tree.op.span.end), "`")
11011103
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//> using options -Werror
2+
3+
import language.`3.4`
4+
5+
class Foo:
6+
def x(i: Int) = i
7+
infix def y(i: Int) = i
8+
9+
def test(foo: Foo): Unit =
10+
foo x 1 // error (because it was compiled with 3.4+)
11+
foo y 2 // ok: is marked as infix
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- Error: tests/neg/alphanumeric-infix-operator.scala:8:6 --------------------------------------------------------------
2+
8 | foo x 1 // error (because it was compiled with 3.4+)
3+
| ^
4+
| Alphanumeric method x is not declared infix; it should not be used as infix operator.
5+
| Instead, use method syntax .x(...) or backticked identifier `x`.
6+
| The latter can be rewritten automatically under -rewrite -source 3.4-migration.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//> using options -Werror
2+
3+
class Foo:
4+
def x(i: Int) = i
5+
infix def y(i: Int) = i
6+
7+
def test(foo: Foo): Unit =
8+
foo x 1 // error (because it was compiled with 3.4+)
9+
foo y 2 // ok: is marked as infix
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class A:
2+
def x(i: Int) = i
3+
infix def y(i: Int) = i
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class B:
2+
def x(i: Int) = i
3+
infix def y(i: Int) = i
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class C:
2+
def x(i: Int) = i
3+
infix def y(i: Int) = i
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class D:
2+
def x(i: Int) = i
3+
infix def y(i: Int) = i
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//> using options -Werror
2+
3+
import language.`3.4`
4+
5+
def test1(a: A, b: B, c: C, d: D): Unit =
6+
a x 1 // ok: was compiled with 3.0
7+
b x 1 // ok: was compiled with 3.1
8+
c x 1 // ok: was compiled with 3.2
9+
d x 1 // ok: was compiled with 3.3
10+
11+
12+
// ok: is marked as infix
13+
a y 2
14+
b y 2
15+
c y 2
16+
d y 2
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import language.future
2+
3+
def test2(a: A, b: B, c: C, d: D): Unit =
4+
a x 1 // ok: was compiled with 3.0
5+
b x 1 // ok: was compiled with 3.1
6+
c x 1 // ok: was compiled with 3.2
7+
d x 1 // ok: was compiled with 3.3
8+
9+
// ok: is marked as infix
10+
a y 2
11+
b y 2
12+
c y 2
13+
d y 2

0 commit comments

Comments
 (0)