Skip to content

Commit

Permalink
Infix type args dropped in Scala 3
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Jan 5, 2023
1 parent 18e2487 commit 8ef8560
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 2 deletions.
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

0 comments on commit 8ef8560

Please sign in to comment.