Skip to content

Commit

Permalink
Merge pull request #14562 from dotty-staging/fix-scanner-lookahead
Browse files Browse the repository at this point in the history
Fix lookahead logic in Scanner
  • Loading branch information
odersky authored Feb 25, 2022
2 parents 2ecde3a + 582536e commit 0b3dd14
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
35 changes: 15 additions & 20 deletions compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -321,30 +321,27 @@ object Scanners {
case _ =>
}

/** Produce next token, filling TokenData fields of Scanner.
*/
def nextToken(): Unit = {
val lastToken = token
adjustSepRegions(lastToken)

// Read a token or copy it from `next` tokenData
if (next.token == EMPTY) {
/** Read a token or copy it from `next` tokenData */
private def getNextToken(lastToken: Token): Unit =
if next.token == EMPTY then
lastOffset = lastCharOffset
currentRegion match {
currentRegion match
case InString(multiLine, _) if lastToken != STRINGPART => fetchStringPart(multiLine)
case _ => fetchToken()
}
if (token == ERROR) adjustSepRegions(STRINGLIT) // make sure we exit enclosing string literal
}
else {
if token == ERROR then adjustSepRegions(STRINGLIT) // make sure we exit enclosing string literal
else
this.copyFrom(next)
next.token = EMPTY
}

if (isAfterLineEnd) handleNewLine(lastToken)
/** Produce next token, filling TokenData fields of Scanner.
*/
def nextToken(): Unit =
val lastToken = token
adjustSepRegions(lastToken)
getNextToken(lastToken)
if isAfterLineEnd then handleNewLine(lastToken)
postProcessToken()
printState()
}

final def printState() =
if debugTokenStream && (showLookAheadOnDebug || !isInstanceOf[LookaheadScanner]) then
Expand Down Expand Up @@ -602,12 +599,10 @@ object Scanners {
insert(OUTDENT, offset)
case _ =>

def lookAhead() = {
def lookAhead() =
prev.copyFrom(this)
lastOffset = lastCharOffset
fetchToken()
getNextToken(token)
if token == END && !isEndMarker then token = IDENTIFIER
}

def reset() = {
next.copyFrom(this)
Expand Down
2 changes: 1 addition & 1 deletion 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 // error
q"class $_" // error // error
}
}
5 changes: 5 additions & 0 deletions tests/pos/fewer-braces.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import language.experimental.fewerBraces

object Test:

assert((new Object: Any).isInstanceOf[Object])

0 comments on commit 0b3dd14

Please sign in to comment.