Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9567 from som-snytt/issue/12071
- Loading branch information
Showing
12 changed files
with
207 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// scalac: -Werror -Xsource:3 | ||
// scalac: -Werror -Xlint -Xsource:3 | ||
|
||
class Test { | ||
val x = 1 | ||
+ 2 | ||
+3 // error: Expected a toplevel definition | ||
+3 // warning: a pure expression does nothing in statement position | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,9 @@ | ||
stmt-expr-discard.scala:5: warning: Line starts with an operator that in future | ||
will be taken as an infix expression continued from the previous line. | ||
To force the previous interpretation as a separate statement, | ||
add an explicit `;`, add an empty line, or remove spaces after the operator. | ||
+ 2 | ||
^ | ||
stmt-expr-discard.scala:6: warning: Line starts with an operator that in future | ||
will be taken as an infix expression continued from the previous line. | ||
To force the previous interpretation as a separate statement, | ||
add an explicit `;`, add an empty line, or remove spaces after the operator. | ||
- 4 | ||
^ | ||
stmt-expr-discard.scala:5: warning: a pure expression does nothing in statement position; multiline expressions may require enclosing parentheses | ||
+ 2 | ||
^ | ||
stmt-expr-discard.scala:6: warning: a pure expression does nothing in statement position; multiline expressions may require enclosing parentheses | ||
- 4 | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
4 warnings | ||
2 warnings | ||
1 error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
t12071.scala:15: error: not found: value c c | ||
`c c` i | ||
^ | ||
t12071.scala:15: error: postfix operator i needs to be enabled | ||
by making the implicit value scala.language.postfixOps visible. | ||
This can be achieved by adding the import clause 'import scala.language.postfixOps' | ||
or by setting the compiler option -language:postfixOps. | ||
See the Scaladoc for value scala.language.postfixOps for a discussion | ||
why the feature needs to be explicitly enabled. | ||
Line starts with an operator that in future | ||
will be taken as an infix expression continued from the previous line. | ||
To force the previous interpretation as a separate statement, | ||
add an explicit `;`, add an empty line, or remove spaces after the operator. | ||
`c c` i | ||
^ | ||
t12071.scala:20: warning: Line starts with an operator that in future | ||
will be taken as an infix expression continued from the previous line. | ||
To force the previous interpretation as a separate statement, | ||
add an explicit `;`, add an empty line, or remove spaces after the operator. | ||
+ 2 | ||
^ | ||
t12071.scala:25: warning: Line starts with an operator that in future | ||
will be taken as an infix expression continued from the previous line. | ||
To force the previous interpretation as a separate statement, | ||
add an explicit `;`, add an empty line, or remove spaces after the operator. | ||
+ 1 | ||
^ | ||
t12071.scala:28: warning: Line starts with an operator that in future | ||
will be taken as an infix expression continued from the previous line. | ||
To force the previous interpretation as a separate statement, | ||
add an explicit `;`, add an empty line, or remove spaces after the operator. | ||
`test-1` + `test-2` | ||
^ | ||
t12071.scala:31: warning: Line starts with an operator that in future | ||
will be taken as an infix expression continued from the previous line. | ||
To force the previous interpretation as a separate statement, | ||
add an explicit `;`, add an empty line, or remove spaces after the operator. | ||
`compareTo` (2 - 1) | ||
^ | ||
4 warnings | ||
2 errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// scalac: -Werror -Xlint -Xmigration:2.13 | ||
|
||
class C { | ||
def `c c`(n: Int): Int = n + 1 | ||
} | ||
|
||
// backticked operator is candidate for multiline infix, | ||
// but backticked value is an innocent bystander. | ||
// | ||
class t12071 { | ||
def c: C = ??? | ||
def i: Int = 42 | ||
def `n n`: Int = 17 | ||
def f = c | ||
`c c` i | ||
def g = i + | ||
`n n` | ||
def basic = | ||
1 | ||
+ 2 | ||
} | ||
|
||
object C { | ||
def x = 42 | ||
+ 1 | ||
|
||
def y = 1 + | ||
`test-1` + `test-2` | ||
|
||
def z = 2 | ||
`compareTo` (2 - 1) | ||
|
||
def `test-1`: Int = 23 | ||
def `test-2`: Int = 42 | ||
def compareTo(x: Int) = println("lol") | ||
|
||
def yy = 1 | ||
/* fails in scala 3 | ||
+ | ||
`test-1` | ||
+ | ||
`test-2` | ||
*/ | ||
} | ||
|
||
object Test extends App { | ||
println(C.x) | ||
println(C.y) | ||
println(C.z) | ||
println(C.yy) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// scalac: -Xsource:3 | ||
// | ||
object HelloWorld { | ||
def whileLoop: Int = { | ||
var i = 0 | ||
var acc = 0 | ||
while (i < 3) { | ||
var `i'` = 0 | ||
while (`i'` < 4) { | ||
acc += (i * `i'`) | ||
`i'` += 1 | ||
} | ||
i += 1 | ||
} | ||
acc | ||
} | ||
|
||
def main(args: Array[String]): Unit = { | ||
println(s"hello world: ${whileLoop}") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
// scalac: -Xsource:3 | ||
|
||
trait T { | ||
def f(x: Int): Boolean = | ||
x < 0 | ||
|| | ||
x > 0 | ||
&& | ||
x != 3 | ||
|
||
def g(x: Option[Int]) = x match { | ||
case Some(err) => | ||
println("hi") | ||
??? | ||
case None => | ||
??? | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
// scalac: -Xsource:3 | ||
// | ||
// without backticks, "not found: value +" | ||
// was: without backticks, "not found: value +" (but parsed here as +a * 6, where backticks fool the lexer) | ||
// now: + is taken as "solo" infix op | ||
// | ||
object Test extends App { | ||
val a = 7 | ||
val x = 1 | ||
+ // | ||
`a` * 6 | ||
+ | ||
`a` | ||
* | ||
6 | ||
|
||
assert(x == 1) | ||
assert(x == 1 + 7 * 6, x) // was: 1, now: successor(42) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// scalac: -Werror -Xlint -Xsource:3 | ||
|
||
class C { | ||
def `c c`(n: Int): Int = n + 1 | ||
} | ||
|
||
// backticked operator is candidate for multiline infix, | ||
// but backticked value is an innocent bystander. | ||
// | ||
class t12071 { | ||
def c: C = new C | ||
def i: Int = 42 | ||
def `n n`: Int = 27 | ||
def f = c | ||
`c c` i | ||
def g = i + | ||
`n n` | ||
def basic = | ||
1 | ||
+ 2 | ||
} | ||
|
||
object Test extends App { | ||
val t = new t12071 | ||
assert(t.f == 43) | ||
assert(t.g == 69) | ||
assert(t.basic == 3) | ||
} |