From 59556fd4510d7b22b0e3c3dbeca648fa63b6d6c6 Mon Sep 17 00:00:00 2001 From: odersky Date: Sat, 11 Jun 2022 16:14:03 +0200 Subject: [PATCH] Defensive code to make sure there's no infinite loop in `skip`. --- compiler/src/dotty/tools/dotc/parsing/Scanners.scala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala index 93ce23cbc103..f987ecd595fe 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala @@ -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])