From 88afd4ac8a9260b639a39abb06122ca535b0794d Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Thu, 5 Jan 2023 12:04:22 -0800 Subject: [PATCH] Infix type args dropped in Scala 3 --- .../scala/tools/nsc/ast/parser/Parsers.scala | 7 ++++++- test/files/neg/dotless-targs-a.check | 15 +++++++++++++++ test/files/neg/dotless-targs-a.scala | 10 ++++++++++ test/files/neg/dotless-targs-b.check | 10 ++++++++++ test/files/neg/dotless-targs-b.scala | 10 ++++++++++ test/files/neg/dotless-targs-ranged-a.check | 16 ++++++++++++++++ test/files/neg/dotless-targs-ranged-a.scala | 16 ++++++++++++++++ test/files/neg/dotless-targs.check | 2 +- test/files/neg/dotless-targs.scala | 2 ++ test/files/run/t10751.check | 1 + test/files/run/t1980.check | 1 + 11 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 test/files/neg/dotless-targs-a.check create mode 100644 test/files/neg/dotless-targs-a.scala create mode 100644 test/files/neg/dotless-targs-b.check create mode 100644 test/files/neg/dotless-targs-b.scala create mode 100644 test/files/neg/dotless-targs-ranged-a.check create mode 100644 test/files/neg/dotless-targs-ranged-a.scala diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 52dfb25d6028..ab125e793582 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -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) diff --git a/test/files/neg/dotless-targs-a.check b/test/files/neg/dotless-targs-a.check new file mode 100644 index 000000000000..e16d2b2e4c70 --- /dev/null +++ b/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 diff --git a/test/files/neg/dotless-targs-a.scala b/test/files/neg/dotless-targs-a.scala new file mode 100644 index 000000000000..1112f676c2da --- /dev/null +++ b/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) +} diff --git a/test/files/neg/dotless-targs-b.check b/test/files/neg/dotless-targs-b.check new file mode 100644 index 000000000000..6aafb4db9157 --- /dev/null +++ b/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 diff --git a/test/files/neg/dotless-targs-b.scala b/test/files/neg/dotless-targs-b.scala new file mode 100644 index 000000000000..d54344238a9a --- /dev/null +++ b/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) +} diff --git a/test/files/neg/dotless-targs-ranged-a.check b/test/files/neg/dotless-targs-ranged-a.check new file mode 100644 index 000000000000..870784528580 --- /dev/null +++ b/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 diff --git a/test/files/neg/dotless-targs-ranged-a.scala b/test/files/neg/dotless-targs-ranged-a.scala new file mode 100644 index 000000000000..9e014c1f0386 --- /dev/null +++ b/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 +} + diff --git a/test/files/neg/dotless-targs.check b/test/files/neg/dotless-targs.check index 4b22dd63e521..e85ded85bb4c 100644 --- a/test/files/neg/dotless-targs.check +++ b/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 diff --git a/test/files/neg/dotless-targs.scala b/test/files/neg/dotless-targs.scala index eff63cbec4f9..70e01c9a00a4 100644 --- a/test/files/neg/dotless-targs.scala +++ b/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 diff --git a/test/files/run/t10751.check b/test/files/run/t10751.check index 0142b6896a14..84258d9452e2 100644 --- a/test/files/run/t10751.check +++ b/test/files/run/t10751.check @@ -35,3 +35,4 @@ } } +warning: 4 deprecations (since 2.13.11); re-run with -deprecation for details diff --git a/test/files/run/t1980.check b/test/files/run/t1980.check index aebd8425db7c..c4e42211b36c 100644 --- a/test/files/run/t1980.check +++ b/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