Skip to content

Fix lookahead logic in Scanner #14562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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])