Skip to content

Commit c7215a6

Browse files
committed
Refactor code and check for errors in typeIdent
1 parent f3833e4 commit c7215a6

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -543,24 +543,22 @@ object Parsers {
543543
}
544544

545545
/** Accept identifier and return Ident with its name as a term name. */
546-
def termIdent(): Ident = {
547-
val lastOffset = in.lastOffset
548-
val id = atPos(in.offset) {
549-
makeIdent(in.token, ident())
550-
}
551-
// Make sure that even trees with parsing errors have a offset that is within the offset
552-
if (id.name == nme.ERROR && id.pos == NoPosition) atPos(lastOffset - 1)(id)
553-
else id
546+
def termIdent(): Ident = atPos(in.offset) {
547+
makeIdent(in.token, ident())
554548
}
555549

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

561-
private def makeIdent(tok: Token, name: Name) =
562-
if (tok == BACKQUOTED_IDENT) BackquotedIdent(name)
563-
else Ident(name)
555+
private def makeIdent(tok: Token, name: Name) = {
556+
val tree =
557+
if (tok == BACKQUOTED_IDENT) BackquotedIdent(name)
558+
else Ident(name)
559+
if (name.toTermName == nme.ERROR) tree.withPos(Position(in.offset, in.offset))
560+
else tree
561+
}
564562

565563
def wildcardIdent(): Ident =
566564
atPos(accept(USCORE)) { Ident(nme.WILDCARD) }

0 commit comments

Comments
 (0)