Skip to content

Commit

Permalink
Merge pull request #15421 from dotty-staging/fix-parser-loop
Browse files Browse the repository at this point in the history
Fix loop in parser
  • Loading branch information
odersky authored Jun 13, 2022
2 parents 1e09221 + 59556fd commit 5332a12
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 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 @@ -2738,14 +2738,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) { Ident(tpnme.WILDCARD_STAR) })
case _ =>
syntaxError(em"`*` must follow pattern variable", start)
p
else p

/** Pattern2 ::= [id `@'] Pattern3
Expand Down
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,13 @@ object Scanners {
// when skipping and therefore might erroneously end up syncing on a nested OUTDENT.
if debugTokenStream then
println(s"\nSTART SKIP AT ${sourcePos().line + 1}, $this in $currentRegion")
while !atStop do
var noProgress = 0
// Defensive measure to ensure we always get out of the following while loop
// even if source file is weirly formatted (i.e. we never reach EOF
while !atStop && noProgress < 3 do
val prevOffset = offset
nextToken()
if offset == prevOffset then noProgress += 1 else noProgress = 0
if debugTokenStream then
println(s"\nSTOP SKIP AT ${sourcePos().line + 1}, $this in $currentRegion")
if token == OUTDENT then dropUntil(_.isInstanceOf[Indented])
Expand Down

0 comments on commit 5332a12

Please sign in to comment.