Skip to content

Commit 0f7b1b0

Browse files
committed
Prevent position errors on Ident(nme.ERROR)
``` Exception in thread "main" java.lang.AssertionError: assertion failed: position error: position not set for Ident(<error>) # 24 at dotty.DottyPredef$.assertFail(DottyPredef.scala:36) at dotty.tools.dotc.ast.Positioned.check$1(Positioned.scala:178) at dotty.tools.dotc.ast.Positioned.check$5$$anonfun$4(Positioned.scala:203) ```
1 parent 9b42731 commit 0f7b1b0

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,16 @@ object Parsers {
518518
}
519519

520520
/** Accept identifier and return Ident with its name as a term name. */
521-
def termIdent(): Ident = atPos(in.offset) {
522-
makeIdent(in.token, ident())
521+
def termIdent(): Ident = {
522+
val start = in.offset
523+
val id = makeIdent(in.token, ident())
524+
if (id.name != nme.ERROR) {
525+
atPos(start)(id)
526+
} else {
527+
// error identifiers don't consume any characters, so atPos(start)(id) wouldn't set a position.
528+
// Some testcases would then fail in Positioned.checkPos. Set a position anyway!
529+
atPos(start, start, in.lastOffset)(id)
530+
}
523531
}
524532

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

tests/neg/parser-stability-23.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object i0 {
2+
import Ordering.{ implicitly => } (true: Boolean) match { case _: i1 => true } // error // error
3+
}

0 commit comments

Comments
 (0)