From a40608871a08731d7cff12d0d8fd702fa831da34 Mon Sep 17 00:00:00 2001 From: i10416 Date: Fri, 26 Jan 2024 06:06:42 +0900 Subject: [PATCH] fix(16459): add patch to syntax error 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 _ @
empty
<- Seq(xml)) yield () ``` but the following resulted in syntax error. ```scala for (case _ @
empty
<-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. [Cherry-picked 3d156b6257ae7dba6085528a636e58179a7e9b14] --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 1 + tests/run/i16459.scala | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index b8db7fc02757..5fc6bf539ac0 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -911,6 +911,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() diff --git a/tests/run/i16459.scala b/tests/run/i16459.scala index 2eee132ecd2c..2964928d522c 100644 --- a/tests/run/i16459.scala +++ b/tests/run/i16459.scala @@ -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 _ @ FooBar <- Seq(xml) if true) + yield () // Note: These pass in Scala 2.12.18 and 2.13.12. val auxiliary9 = for (case _ @ FooBar<- Seq(xml) if true) + yield () val auxiliary10 = for (case _ @ FooBar<-Seq(xml) if true) - yield () + yield () }