Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate infix type args, as they are dropped in Scala 3 #10255

Merged
merged 1 commit into from Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
Expand Up @@ -986,10 +986,15 @@ self =>

def finishBinaryOp(isExpr: Boolean, opinfo: OpInfo, rhs: Tree): Tree = {
import opinfo._
if (targs.nonEmpty)
if (currentRun.isScala3)
syntaxError(offset, "type application is not allowed for infix operators")
else
deprecationWarning(offset, "type application will be disallowed for infix operators", "2.13.11")
val operatorPos: Position = Position.range(rhs.pos.source, offset, offset, offset + operator.length)
val pos = lhs.pos.union(rhs.pos).union(operatorPos).withEnd(in.lastOffset).withPoint(offset)

atPos(pos)(makeBinop(isExpr, lhs, operator, rhs, operatorPos, opinfo.targs))
atPos(pos)(makeBinop(isExpr, lhs, operator, rhs, operatorPos, targs))
}

def reduceExprStack(base: List[OpInfo], top: Tree): Tree = reduceStack(isExpr = true, base, top)
Expand Down
15 changes: 15 additions & 0 deletions test/files/neg/dotless-targs-a.check
@@ -0,0 +1,15 @@
dotless-targs-a.scala:4: warning: type application will be disallowed for infix operators
def fn2 = List apply[Int] 2
^
dotless-targs-a.scala:9: warning: type application will be disallowed for infix operators
def h1 = List apply[List[Int]] (List(1), List(2)) mapConserve[List[Any]] (x => x)
^
dotless-targs-a.scala:9: warning: type application will be disallowed for infix operators
def h1 = List apply[List[Int]] (List(1), List(2)) mapConserve[List[Any]] (x => x)
^
dotless-targs-a.scala:9: warning: multiarg infix syntax looks like a tuple and will be deprecated
def h1 = List apply[List[Int]] (List(1), List(2)) mapConserve[List[Any]] (x => x)
^
error: No warnings can be incurred under -Werror.
4 warnings
1 error
10 changes: 10 additions & 0 deletions test/files/neg/dotless-targs-a.scala
@@ -0,0 +1,10 @@
// scalac: -Werror -Xlint -Yrangepos:false
class A {
def fn1 = List apply 1
def fn2 = List apply[Int] 2

def g1: Char = "g1" toList 0
def g2: Char = "g2" apply 1

def h1 = List apply[List[Int]] (List(1), List(2)) mapConserve[List[Any]] (x => x)
}
10 changes: 10 additions & 0 deletions test/files/neg/dotless-targs-b.check
@@ -0,0 +1,10 @@
dotless-targs-b.scala:4: error: type application is not allowed for infix operators
def fn2 = List apply[Int] 2
^
dotless-targs-b.scala:9: error: type application is not allowed for infix operators
def h1 = List apply[List[Int]] (List(1), List(2)) mapConserve[List[Any]] (x => x)
^
dotless-targs-b.scala:9: error: type application is not allowed for infix operators
def h1 = List apply[List[Int]] (List(1), List(2)) mapConserve[List[Any]] (x => x)
^
3 errors
10 changes: 10 additions & 0 deletions test/files/neg/dotless-targs-b.scala
@@ -0,0 +1,10 @@
// scalac: -Werror -Xlint -Xsource:3 -Yrangepos:false
class A {
def fn1 = List apply 1
def fn2 = List apply[Int] 2

def g1: Char = "g1" toList 0
def g2: Char = "g2" apply 1

def h1 = List apply[List[Int]] (List(1), List(2)) mapConserve[List[Any]] (x => x)
}
16 changes: 16 additions & 0 deletions test/files/neg/dotless-targs-ranged-a.check
@@ -0,0 +1,16 @@
dotless-targs-ranged-a.scala:4: error: type application is not allowed for infix operators
def fn2 = List apply[Int] 2
^
dotless-targs-ranged-a.scala:9: error: type application is not allowed for infix operators
def h1 = List apply[List[Int]] (List(1), List(2)) mapConserve[List[Any]] (x => x)
^
dotless-targs-ranged-a.scala:9: error: type application is not allowed for infix operators
def h1 = List apply[List[Int]] (List(1), List(2)) mapConserve[List[Any]] (x => x)
^
dotless-targs-ranged-a.scala:13: error: type application is not allowed for infix operators
def eval = 1 ->[Int] 2
^
dotless-targs-ranged-a.scala:14: error: type application is not allowed for infix operators
def evil = new A() op [Int, String ] 42
^
5 errors
16 changes: 16 additions & 0 deletions test/files/neg/dotless-targs-ranged-a.scala
@@ -0,0 +1,16 @@
// scalac: -Xlint -Xsource:3 -Yrangepos:true
class A {
def fn1 = List apply 1
def fn2 = List apply[Int] 2

def g1: Char = "g1" toList 0
def g2: Char = "g2" apply 1

def h1 = List apply[List[Int]] (List(1), List(2)) mapConserve[List[Any]] (x => x)

def op[A, B](i: Int): Int = 2*i

def eval = 1 ->[Int] 2
def evil = new A() op [Int, String ] 42
}

2 changes: 1 addition & 1 deletion test/files/neg/dotless-targs.check
@@ -1,4 +1,4 @@
dotless-targs.scala:2: error: type application is not allowed for postfix operators
dotless-targs.scala:4: error: type application is not allowed for postfix operators
def f1 = "f1" isInstanceOf[String] // not ok
^
1 error
2 changes: 2 additions & 0 deletions test/files/neg/dotless-targs.scala
@@ -1,3 +1,5 @@
// scalac: -Xsource:3 -language:postfixOps
//
class A {
def f1 = "f1" isInstanceOf[String] // not ok
def f2 = "f2".isInstanceOf[String] // ok
Expand Down
1 change: 1 addition & 0 deletions test/files/run/t10751.check
Expand Up @@ -35,3 +35,4 @@
}
}

warning: 4 deprecations (since 2.13.11); re-run with -deprecation for details
1 change: 1 addition & 0 deletions test/files/run/t1980.check
@@ -1,3 +1,4 @@
warning: 1 deprecation (since 2.13.11); re-run with -deprecation for details
1. defining
foo 1
foo 2
Expand Down