From 455ad65f336fb38312156af5ad17ddf256645952 Mon Sep 17 00:00:00 2001 From: odersky Date: Sat, 11 Jun 2022 10:49:40 +0200 Subject: [PATCH] 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). ` --- .../src/dotty/tools/dotc/parsing/Parsers.scala | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index bdf19ac7d013..846bbf64f514 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -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