Skip to content

Commit

Permalink
Avoid infinite loop in parser
Browse files Browse the repository at this point in the history
Parser could get into an infinite loop because `acceptStatSepUnlessAtEnd`
did not make progress. I believe the concrete example was a string interpolator
where we encounter a `{ ... )`.
  • Loading branch information
odersky committed Jul 29, 2017
1 parent 87f375c commit 4af2401
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,16 @@ object Parsers {
}

def acceptStatSepUnlessAtEnd(altEnd: Token = EOF) =
if (!isStatSeqEnd && in.token != altEnd) acceptStatSep()
if (!isStatSeqEnd)
in.token match {
case EOF =>
case `altEnd` =>
case NEWLINE | NEWLINES => in.nextToken()
case SEMI => in.nextToken()
case _ =>
in.nextToken() // needed to ensure progress; otherwise we might cycle forever
accept(SEMI)
}

def errorTermTree = atPos(in.offset) { Literal(Constant(null)) }

Expand Down
4 changes: 2 additions & 2 deletions tests/neg/i1779.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ object Test {
def f = {
val _parent = 3
q"val hello = $_parent"
q"class $_" // error // error
}
q"class $_" // error
} // error
}

0 comments on commit 4af2401

Please sign in to comment.