Skip to content

Commit baa6e95

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

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,12 @@ 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+
// Make sure that even trees with parsing errors have a offset that is within the offset
548+
val offset = if (in.offset <= in.lastOffset) in.offset else in.lastOffset - 1
549+
atPos(offset) {
550+
makeIdent(in.token, ident())
551+
}
548552
}
549553

550554
/** 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

0 commit comments

Comments
 (0)