summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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())