Skip to content

Commit

Permalink
Defensive code to make sure there's no infinite loop in skip.
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Jun 11, 2022
1 parent ed658ee commit 59556fd
Showing 1 changed file with 6 additions and 1 deletion.
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 59556fd

Please sign in to comment.