Skip to content

Commit a0d6a55

Browse files
committed
Fix #5032: Make sure that erroneous empty idents have a position
1 parent e873908 commit a0d6a55

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,14 @@ 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())
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
555561
}
556562

557563
/** Accept identifier and return Ident with its name as a type name. */

tests/neg/i5032a.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class i1@
2+
// error

tests/neg/i5032b.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class a@
2+
class b@ // error // error

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 // error
14+
f[X = Int, String](1, "") // error: ']' expected, but `=` found
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)