Skip to content

Fix #5032: Make sure that erroneous empty idents have a position #5706

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 4 commits into from
Jan 23, 2019
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
23 changes: 14 additions & 9 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -550,18 +550,23 @@ object Parsers {
}

/** Accept identifier and return Ident with its name as a term name. */
def termIdent(): Ident = atSpan(in.offset) {
makeIdent(in.token, ident())
}
def termIdent(): Ident =
makeIdent(in.token, in.offset, ident())

/** Accept identifier and return Ident with its name as a type name. */
def typeIdent(): Ident = atSpan(in.offset) {
makeIdent(in.token, ident().toTypeName)
}
def typeIdent(): Ident =
makeIdent(in.token, in.offset, ident().toTypeName)

private def makeIdent(tok: Token, name: Name) =
if (tok == BACKQUOTED_IDENT) BackquotedIdent(name)
else Ident(name)
private def makeIdent(tok: Token, offset: Offset, name: Name) = {
val tree =
if (tok == BACKQUOTED_IDENT) BackquotedIdent(name)
else Ident(name)

// Make sure that even trees with parsing errors have a offset that is within the offset
val errorOffset = offset min (in.lastOffset - 1)
if (tree.name == nme.ERROR && tree.span == NoSpan) tree.withSpan(Span(errorOffset, errorOffset))
else atSpan(offset)(tree)
}

def wildcardIdent(): Ident =
atSpan(accept(USCORE)) { Ident(nme.WILDCARD) }
Expand Down
2 changes: 2 additions & 0 deletions tests/neg/i5032a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class i1@
// error
2 changes: 2 additions & 0 deletions tests/neg/i5032b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class a@
class b@ // error // error