Skip to content

Commit 11e905a

Browse files
committed
syntax.md: support multiple if-guards on same line
Consider the example: ```scala for { x <- 1 to 5 if true; if true; if true } yield x ``` Note, that multiple if guards start from a new line and are not separated with a semicolon or a new line. This code is compiled ok in Scala 3 and is a valid code according to Scala 2 syntax reference: (though looks like there is a bug in implementation scala/bug#12323) But it's not supported according to the Scala 3 syntax reference. related issues: scala/bug#12323 https://youtrack.jetbrains.com/issue/SCL-13220
1 parent 49c59f5 commit 11e905a

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2459,7 +2459,7 @@ object Parsers {
24592459
else Nil
24602460

24612461
/** Enumerator ::= Generator
2462-
* | Guard
2462+
* | Guard {Guard}
24632463
* | Pattern1 `=' Expr
24642464
*/
24652465
def enumerator(): Tree =

docs/docs/internals/syntax.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ ForExpr ::= ‘for’ (‘(’ Enumerators ‘)’ | ‘{’ Enumerat
269269
| ‘for’ Enumerators (‘do’ Expr | ‘yield’ Expr) ForDo(enums, expr)
270270
Enumerators ::= Generator {semi Enumerator | Guard}
271271
Enumerator ::= Generator
272-
| Guard
272+
| Guard {Guard}
273273
| Pattern1 ‘=’ Expr GenAlias(pat, expr)
274-
Generator ::= [‘case’] Pattern1 ‘<-’ Expr GenFrom(pat, expr)
274+
Generator ::= [‘case’] Pattern1 ‘<-’ Expr GenFrom(pat, expr)
275275
Guard ::= ‘if’ PostfixExpr
276276
277277
CaseClauses ::= CaseClause { CaseClause } Match(EmptyTree, cases)

docs/docs/reference/syntax.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ ForExpr ::= ‘for’ (‘(’ Enumerators ‘)’ | ‘{’ Enumerat
264264
| ‘for’ Enumerators (‘do’ Expr | ‘yield’ Expr)
265265
Enumerators ::= Generator {semi Enumerator | Guard}
266266
Enumerator ::= Generator
267-
| Guard
268-
| Pattern1 ‘=’ Expr
269-
Generator ::= [‘case’] Pattern1 ‘<-’ Expr
267+
| Guard {Guard}
268+
| Pattern1 ‘=’ Expr GenAlias(pat, expr)
269+
Generator ::= [‘case’] Pattern1 ‘<-’ Expr GenFrom(pat, expr)
270270
Guard ::= ‘if’ PostfixExpr
271271
272272
CaseClauses ::= CaseClause { CaseClause }

0 commit comments

Comments
 (0)