summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-08-08 06:56:45 +0000
committerPaul Phillips <paulp@improving.org>2011-08-08 06:56:45 +0000
commit5b11f250ce650b8c66134e6ae6a9f48b3c82f64a (patch)
tree79cbf7ce3b6c30da09b6fd61493ca6872eaa4871
parent8b28292b5379a34fad0599335116b9e54ee44e20 (diff)
downloadscala-5b11f250ce650b8c66134e6ae6a9f48b3c82f64a.tar.gz
scala-5b11f250ce650b8c66134e6ae6a9f48b3c82f64a.tar.bz2
scala-5b11f250ce650b8c66134e6ae6a9f48b3c82f64a.zip
When I tried to remove the old for comprehensio...
When I tried to remove the old for comprehension syntax in r24958, I managed to instead only remove the deprecation warnings. No wonder it went so smoothly. Sorry to get your hopes up only to execute you, old syntax. Now the for comprehensions have to get it right: for (x <- 1 to 5 ; y = x) yield x+y // nope for (val x <- 1 to 5 ; y = x) yield x+y // nope for (val x <- 1 to 5 ; val y = x) yield x+y // nope for (x <- 1 to 5 ; val y = x) yield x+y // that's the one No review.
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index 68651fc1c9..28cb088f4e 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -1631,15 +1631,24 @@ self =>
* }}}
*/
def generator(enums: ListBuffer[Enumerator], eqOK: Boolean) {
- val start = in.offset
- if (in.token == VAL) in.nextToken()
- val pat = noSeq.pattern1()
+ val start = in.offset
+ val hasVal = in.token == VAL
+ if (hasVal)
+ in.nextToken()
+
+ val pat = noSeq.pattern1()
val point = in.offset
- val tok = in.token
- if (tok == EQUALS && eqOK) in.nextToken()
+ val hasEq = in.token == EQUALS
+
+ if (hasVal && !hasEq)
+ syntaxError(in.offset, "val in for comprehension must be followed by assignment")
+ if (!hasVal && hasEq)
+ syntaxError(in.offset, "assignment in for comprehension must be preceded by `val`")
+
+ if (hasEq && eqOK) in.nextToken()
else accept(LARROW)
val rhs = expr()
- enums += makeGenerator(r2p(start, point, in.lastOffset max start), pat, tok == EQUALS, rhs)
+ enums += makeGenerator(r2p(start, point, in.lastOffset max start), pat, hasEq, rhs)
// why max above? IDE stress tests have shown that lastOffset could be less than start,
// I guess this happens if instead if a for-expression we sit on a closing paren.
while (in.token == IF) enums += makeFilter(in.offset, guard())