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 #8419 from som-snytt/topic/leading-infix
Allow infix operators at start of line
- Loading branch information
Showing
17 changed files
with
192 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
infixed.scala:8: error: ';' expected but integer literal found. | ||
x 42 | ||
^ | ||
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,10 @@ | ||
// scalac: -Xsource:3 | ||
|
||
class K { def x(y: Int) = 0 } | ||
|
||
class Test { | ||
def bad = { | ||
(new K) | ||
x 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,4 @@ | ||
multiLineOps-b.scala:7: error: ';' expected but integer literal found. | ||
*/*one more*/22 // error: end of statement expected | ||
^ | ||
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,9 @@ | ||
// scalac: -Werror -Xsource:2.14 | ||
|
||
class Test { | ||
val b1 = { | ||
22 | ||
* 22 // ok | ||
*/*one more*/22 // error: end of statement expected | ||
} // error: ';' expected, but '}' found | ||
} |
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,5 @@ | ||
multiLineOps-c.scala:7: error: value ! is not a member of Unit | ||
possible cause: maybe a semicolon is missing before `value !`? | ||
! "hello".isEmpty // error: value ! is not a member of Unit | ||
^ | ||
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,9 @@ | ||
// scalac: -Werror -Xsource:2.14 | ||
|
||
class Test { | ||
val x = 42 | ||
val b2: Boolean = { | ||
println(x) | ||
! "hello".isEmpty // error: value ! is not a member of Unit | ||
} | ||
} |
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,6 @@ | ||
multiLineOps.scala:6: warning: a pure expression does nothing in statement position; multiline expressions may require enclosing parentheses | ||
+3 // error: Expected a toplevel definition | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
1 warning | ||
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,7 @@ | ||
// scalac: -Werror -Xsource:2.14 | ||
|
||
class Test { | ||
val x = 1 | ||
+ 2 | ||
+3 // error: Expected a toplevel definition | ||
} |
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,9 +1,21 @@ | ||
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. | ||
2 warnings | ||
4 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// scalac: -Xfatal-warnings | ||
// scalac: -Werror -Xsource:2.13 -Xlint:deprecation | ||
// | ||
class A { | ||
def f = 1 | ||
|
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// scalac: -Xsource:3 | ||
|
||
class K { def x(y: Int) = 0 } | ||
|
||
class Test { | ||
def ok = { | ||
(new K) | ||
`x` 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,30 @@ | ||
// scalac: -Werror -Xsource:2.14 | ||
|
||
class Channel { | ||
def ! (msg: String): Channel = this | ||
def send_! (msg: String): Channel = this | ||
} | ||
|
||
class Test { | ||
val x = 1 | ||
+ 2 | ||
+ 3 | ||
|
||
val c = new Channel() | ||
|
||
def send() = | ||
c ! "hello" | ||
! "world" | ||
send_! "!" | ||
|
||
val b: Boolean = | ||
"hello".isEmpty | ||
&& true && | ||
!"hello".isEmpty | ||
|
||
val b2: Boolean = { | ||
println(x) | ||
!"hello".isEmpty | ||
??? | ||
} | ||
} |
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,12 @@ | ||
// scalac: -Xsource:2.14 | ||
// | ||
// without backticks, "not found: value +" | ||
// | ||
object Test extends App { | ||
val a = 7 | ||
val x = 1 | ||
+ // | ||
`a` * 6 | ||
|
||
assert(x == 1) | ||
} |