Skip to content

Commit ed658ee

Browse files
committed
Fix loop in parser
I noted a case in Metals where the compiler would keep running at 100+ % until the process was killed. Using jstack I tracked it down to an infinite `skip` caused by a `syntaxError` in `pattern3`. In fact, the syntaxError should not skip at this point since the offending expression was already fully parsed. I fixed this in this commit. The parser was invoked from the `signatureHelp` method. It seems it parsed something that was not syntactically correct (specifically, a postfix `*` appeared in a pattern where none was allowed). `
1 parent cec9aa3 commit ed658ee

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2745,14 +2745,13 @@ object Parsers {
27452745
def pattern3(): Tree =
27462746
val p = infixPattern()
27472747
if followingIsVararg() then
2748-
atSpan(in.skipToken()) {
2749-
p match
2750-
case p @ Ident(name) if name.isVarPattern =>
2751-
Typed(p, Ident(tpnme.WILDCARD_STAR))
2752-
case _ =>
2753-
syntaxError(em"`*` must follow pattern variable")
2754-
p
2755-
}
2748+
val start = in.skipToken()
2749+
p match
2750+
case p @ Ident(name) if name.isVarPattern =>
2751+
Typed(p, atSpan(start) { Ident(tpnme.WILDCARD_STAR) })
2752+
case _ =>
2753+
syntaxError(em"`*` must follow pattern variable", start)
2754+
p
27562755
else p
27572756

27582757
/** Pattern2 ::= [id `@'] Pattern3

0 commit comments

Comments
 (0)