Skip to content

Commit 7dbe1e0

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

File tree

15 files changed

+80
-12
lines changed

15 files changed

+80
-12
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
}

language-server/test/dotty/tools/languageserver/util/embedded/CodeMarker.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import PositionContext.PosCtx
1313
class CodeMarker(val name: String) extends Embedded {
1414

1515
/** A range of positions between this marker and `other`. */
16-
def to(other: CodeMarker): CodeRange = CodeRange(this, other)
16+
infix def to(other: CodeMarker): CodeRange = CodeRange(this, other)
1717

1818
/** The file containing this marker. */
1919
def file: PosCtx[TestFile] = posCtx.positionOf(this)._1

scaladoc-testcases/src/tests/infixTypes.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ package infixTypes
44
import annotation.showAsInfix
55

66
@showAsInfix
7-
trait SomeTrait[A, B]
7+
infix trait SomeTrait[A, B]
88

9-
trait SomeTrait2[A, B]
9+
infix trait SomeTrait2[A, B]
1010

1111
def someTrait1[C, D]: C SomeTrait D
1212
= ???

scaladoc/src/dotty/tools/scaladoc/tasty/comments/MemberLookup.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ object MemberLookup extends MemberLookup {
236236
// Scaladoc overloading support allows terminal * (and they're meaningless)
237237
val cleanStr = str.stripSuffix("*")
238238

239-
if cleanStr endsWith "$" then
239+
if cleanStr.endsWith("$") then
240240
Selector(cleanStr.init, SelectorKind.ForceTerm)
241-
else if cleanStr endsWith "!" then
241+
else if cleanStr.endsWith("!") then
242242
Selector(cleanStr.init, SelectorKind.ForceType)
243243
else
244244
Selector(cleanStr, SelectorKind.NoForce)

scaladoc/src/dotty/tools/scaladoc/tasty/comments/wiki/Parser.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ sealed class CharReader(buffer: String) { reader =>
675675

676676
var offset: Int = 0
677677
def char: Char =
678-
if (offset >= buffer.length) endOfText else buffer charAt offset
678+
if (offset >= buffer.length) endOfText else buffer.charAt(offset)
679679

680680
final def nextChar() =
681681
offset += 1
@@ -712,7 +712,7 @@ sealed class CharReader(buffer: String) { reader =>
712712
jumpWhitespace()
713713
val (ok0, chars0) =
714714
if (chars.charAt(0) == ' ')
715-
(offset > poff, chars substring 1)
715+
(offset > poff, chars.substring(1))
716716
else
717717
(true, chars)
718718
val ok = ok0 && jump(chars0)

scaladoc/test/dotty/tools/scaladoc/testUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def tastyFiles(name: String, allowEmpty: Boolean = false, rootPck: String = "tes
7171
}
7272
def collectFiles(dir: File): List[File] = listFilesSafe(dir).toList.flatMap {
7373
case f if f.isDirectory => collectFiles(f)
74-
case f if f.getName endsWith ".tasty" => f :: Nil
74+
case f if f.getName.endsWith(".tasty") => f :: Nil
7575
case _ => Nil
7676
}
7777
val outputDir = BuildInfo.test_testcasesOutputDir
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
// ok: is marked as infix
12+
a y 2
13+
b y 2
14+
c y 2
15+
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)