Skip to content

Commit d362496

Browse files
committed
Refactor code and check for errors in typeIdent
1 parent a0d6a55 commit d362496

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

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

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

552552
/** Accept identifier and return Ident with its name as a term name. */
553-
def termIdent(): Ident = {
554-
val lastOffset = in.lastOffset
555-
val id = atSpan(in.offset) {
556-
makeIdent(in.token, ident())
557-
}
558-
// Make sure that even trees with parsing errors have a offset that is within the offset
559-
if (id.name == nme.ERROR && id.span == NoSpan) atSpan(lastOffset - 1)(id)
560-
else id
553+
def termIdent(): Ident = atSpan(in.offset) {
554+
makeIdent(in.token, ident())
561555
}
562556

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

568-
private def makeIdent(tok: Token, name: Name) =
569-
if (tok == BACKQUOTED_IDENT) BackquotedIdent(name)
570-
else Ident(name)
562+
private def makeIdent(tok: Token, name: Name) = {
563+
val tree =
564+
if (tok == BACKQUOTED_IDENT) BackquotedIdent(name)
565+
else Ident(name)
566+
567+
// Make sure that even trees with parsing errors have a offset that is within the offset
568+
if (tree.name == nme.ERROR && tree.span == NoSpan) tree.withSpan(Span(in.lastOffset - 1, in.lastOffset - 1))
569+
else tree
570+
}
571571

572572
def wildcardIdent(): Ident =
573573
atSpan(accept(USCORE)) { Ident(nme.WILDCARD) }

tests/neg/namedTypeParams.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object Test {
1111

1212
def f[X, Y](x: X, y: Y): Int = ???
1313

14-
f[X = Int, String](1, "") // error: ']' expected, but `=` found
14+
f[X = Int, String](1, "") // error // error
1515
f[X = Int][X = Int][Y = String](1, "") // error: illegal repeated type application
1616

1717
f[X = Int][Y = String](1, "") // error: illegal repeated type application

0 commit comments

Comments
 (0)