Skip to content

Commit 1cb3bdd

Browse files
committed
Factor ident span computation
1 parent 652f94e commit 1cb3bdd

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -550,24 +550,22 @@ object Parsers {
550550
}
551551

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

557556
/** Accept identifier and return Ident with its name as a type name. */
558-
def typeIdent(): Ident = atSpan(in.offset) {
559-
makeIdent(in.token, ident().toTypeName)
560-
}
557+
def typeIdent(): Ident =
558+
makeIdent(in.token, in.offset, ident().toTypeName)
561559

562-
private def makeIdent(tok: Token, name: Name) = {
560+
private def makeIdent(tok: Token, offset: Offset, name: Name) = {
563561
val tree =
564562
if (tok == BACKQUOTED_IDENT) BackquotedIdent(name)
565563
else Ident(name)
566564

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

573571
def wildcardIdent(): Ident =

0 commit comments

Comments
 (0)