Skip to content

Commit

Permalink
Fix loop in parser
Browse files Browse the repository at this point in the history
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).

`
  • Loading branch information
odersky committed Jun 11, 2022
1 parent cec9aa3 commit 455ad65
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2745,14 +2745,13 @@ object Parsers {
def pattern3(): Tree =
val p = infixPattern()
if followingIsVararg() then
atSpan(in.skipToken()) {
p match
case p @ Ident(name) if name.isVarPattern =>
Typed(p, Ident(tpnme.WILDCARD_STAR))
case _ =>
syntaxError(em"`*` must follow pattern variable")
p
}
val start = in.skipToken()
p match
case p @ Ident(name) if name.isVarPattern =>
Typed(p, atSpan(start) { Typed(p, Ident(tpnme.WILDCARD_STAR)) })
case _ =>
syntaxError(em"`*` must follow pattern variable", start)
p
else p

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

0 comments on commit 455ad65

Please sign in to comment.