Skip to content

Commit

Permalink
fix(16459): add patch to syntax error
Browse files Browse the repository at this point in the history
Add a patch to cover the cornercase where xml pattern in parens confuse
the parser.

Before this commit, the following code compiles,

```scala
for (case _ @ <div>empty</div> <- Seq(xml)) yield ()
```
but the following resulted in syntax error.

```scala
for (case _ @ <div>empty</div><-Seq(xml)) yield ()
```

Because `followingIsEnclosedGenerators` always comes after `for` and
`(`, I beleive it would not break the parser to early-exit when
`XMLSTART` is found.
  • Loading branch information
i10416 committed Jan 26, 2024
1 parent 4b0fff5 commit 3d156b6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,7 @@ object Parsers {
lookahead.nextToken()
while (parens != 0 && lookahead.token != EOF) {
val token = lookahead.token
if (token == XMLSTART) return true
if (token == LPAREN) parens += 1
else if (token == RPAREN) parens -= 1
lookahead.nextToken()
Expand Down
4 changes: 3 additions & 1 deletion tests/run/i16459.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ object Test {
// Pattern match with if guard.
// Note: This passes in Scala 2.12.18 and 2.13.12 too.
val auxiliary8 = for (case _ @ <foo>FooBar</foo> <- Seq(xml) if true)
yield ()
// Note: These pass in Scala 2.12.18 and 2.13.12.
val auxiliary9 = for (case _ @ <foo>FooBar</foo><- Seq(xml) if true)
yield ()
val auxiliary10 = for (case _ @ <foo>FooBar</foo><-Seq(xml) if true)
yield ()
yield ()

}

Expand Down

0 comments on commit 3d156b6

Please sign in to comment.