Skip to content

Commit 311043b

Browse files
committed
Fix #5032: Make sure that erroneous empty idents have a position
1 parent c5326ca commit 311043b

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
@@ -543,8 +543,14 @@ object Parsers {
543543
}
544544

545545
/** Accept identifier and return Ident with its name as a term name. */
546-
def termIdent(): Ident = atPos(in.offset) {
547-
makeIdent(in.token, ident())
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
548554
}
549555

550556
/** 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)