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

Remove val in for comprehension under -Xsource:2.14 #6348

Merged
merged 1 commit into from
Apr 30, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1826,7 +1826,7 @@ self =>
* Enumerators ::= Generator {semi Enumerator}
* Enumerator ::= Generator
* | Guard
* | val Pattern1 `=' Expr
* | Pattern1 `=' Expr
* }}}
*/
def enumerators(): List[Tree] = {
Expand Down Expand Up @@ -1858,8 +1858,13 @@ self =>
val hasEq = in.token == EQUALS

if (hasVal) {
if (hasEq) deprecationWarning(in.offset, "val keyword in for comprehension is deprecated", "2.10.0")
else syntaxError(in.offset, "val in for comprehension must be followed by assignment")
def msg(what: String, instead: String): String = s"`val` keyword in for comprehension is $what: $instead"
if (hasEq) {
val without = "instead, bind the value without `val`"
if (settings.isScala214) syntaxError(in.offset, msg("unsupported", without))
else deprecationWarning(in.offset, msg("deprecated", without), "2.10.0")
}
else syntaxError(in.offset, msg("unsupported", "just remove `val`"))
}

if (hasEq && eqOK) in.nextToken()
Expand Down
16 changes: 8 additions & 8 deletions test/files/neg/for-comprehension-old.check
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
for-comprehension-old.scala:3: warning: val keyword in for comprehension is deprecated
for-comprehension-old.scala:3: warning: `val` keyword in for comprehension is deprecated: instead, bind the value without `val`
for (x <- 1 to 5 ; val y = x) yield x+y // fail
^
for-comprehension-old.scala:5: warning: val keyword in for comprehension is deprecated
for-comprehension-old.scala:5: warning: `val` keyword in for comprehension is deprecated: instead, bind the value without `val`
for (val x <- 1 to 5 ; val y = x) yield x+y // fail
^
for-comprehension-old.scala:8: warning: val keyword in for comprehension is deprecated
for-comprehension-old.scala:8: warning: `val` keyword in for comprehension is deprecated: instead, bind the value without `val`
for (z <- 1 to 2 ; x <- 1 to 5 ; val y = x) yield x+y // fail
^
for-comprehension-old.scala:10: warning: val keyword in for comprehension is deprecated
for-comprehension-old.scala:10: warning: `val` keyword in for comprehension is deprecated: instead, bind the value without `val`
for (z <- 1 to 2 ; val x <- 1 to 5 ; val y = x) yield x+y // fail
^
for-comprehension-old.scala:4: error: val in for comprehension must be followed by assignment
for-comprehension-old.scala:4: error: `val` keyword in for comprehension is unsupported: just remove `val`
for (val x <- 1 to 5 ; y = x) yield x+y // fail
^
for-comprehension-old.scala:5: error: val in for comprehension must be followed by assignment
for-comprehension-old.scala:5: error: `val` keyword in for comprehension is unsupported: just remove `val`
for (val x <- 1 to 5 ; val y = x) yield x+y // fail
^
for-comprehension-old.scala:9: error: val in for comprehension must be followed by assignment
for-comprehension-old.scala:9: error: `val` keyword in for comprehension is unsupported: just remove `val`
for (z <- 1 to 2 ; val x <- 1 to 5 ; y = x) yield x+y // fail
^
for-comprehension-old.scala:10: error: val in for comprehension must be followed by assignment
for-comprehension-old.scala:10: error: `val` keyword in for comprehension is unsupported: just remove `val`
for (z <- 1 to 2 ; val x <- 1 to 5 ; val y = x) yield x+y // fail
^
four warnings found
Expand Down
25 changes: 25 additions & 0 deletions test/files/neg/for-comprehension-val.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
for-comprehension-val.scala:3: error: `val` keyword in for comprehension is unsupported: instead, bind the value without `val`
for (x <- 1 to 5 ; val y = x) yield x+y // fail
^
for-comprehension-val.scala:4: error: `val` keyword in for comprehension is unsupported: just remove `val`
for (val x <- 1 to 5 ; y = x) yield x+y // fail
^
for-comprehension-val.scala:5: error: `val` keyword in for comprehension is unsupported: just remove `val`
for (val x <- 1 to 5 ; val y = x) yield x+y // fail
^
for-comprehension-val.scala:5: error: `val` keyword in for comprehension is unsupported: instead, bind the value without `val`
for (val x <- 1 to 5 ; val y = x) yield x+y // fail
^
for-comprehension-val.scala:8: error: `val` keyword in for comprehension is unsupported: instead, bind the value without `val`
for (z <- 1 to 2 ; x <- 1 to 5 ; val y = x) yield x+y // fail
^
for-comprehension-val.scala:9: error: `val` keyword in for comprehension is unsupported: just remove `val`
for (z <- 1 to 2 ; val x <- 1 to 5 ; y = x) yield x+y // fail
^
for-comprehension-val.scala:10: error: `val` keyword in for comprehension is unsupported: just remove `val`
for (z <- 1 to 2 ; val x <- 1 to 5 ; val y = x) yield x+y // fail
^
for-comprehension-val.scala:10: error: `val` keyword in for comprehension is unsupported: instead, bind the value without `val`
for (z <- 1 to 2 ; val x <- 1 to 5 ; val y = x) yield x+y // fail
^
8 errors found
1 change: 1 addition & 0 deletions test/files/neg/for-comprehension-val.flags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-deprecation -Xsource:2.14
11 changes: 11 additions & 0 deletions test/files/neg/for-comprehension-val.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class A {
for (x <- 1 to 5 ; y = x) yield x+y // ok
for (x <- 1 to 5 ; val y = x) yield x+y // fail
for (val x <- 1 to 5 ; y = x) yield x+y // fail
for (val x <- 1 to 5 ; val y = x) yield x+y // fail

for (z <- 1 to 2 ; x <- 1 to 5 ; y = x) yield x+y // ok
for (z <- 1 to 2 ; x <- 1 to 5 ; val y = x) yield x+y // fail
for (z <- 1 to 2 ; val x <- 1 to 5 ; y = x) yield x+y // fail
for (z <- 1 to 2 ; val x <- 1 to 5 ; val y = x) yield x+y // fail
}