Skip to content

Commit d9bf41c

Browse files
Blaisorbladeallanrenucci
authored andcommitted
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 f2efe05 commit d9bf41c

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
@@ -526,8 +526,16 @@ object Parsers {
526526
}
527527

528528
/** Accept identifier and return Ident with its name as a term name. */
529-
def termIdent(): Ident = atPos(in.offset) {
530-
makeIdent(in.token, ident())
529+
def termIdent(): Ident = {
530+
val start = in.offset
531+
val id = makeIdent(in.token, ident())
532+
if (id.name != nme.ERROR) {
533+
atPos(start)(id)
534+
} else {
535+
// error identifiers don't consume any characters, so atPos(start)(id) wouldn't set a position.
536+
// Some testcases would then fail in Positioned.checkPos. Set a position anyway!
537+
atPos(start, start, in.lastOffset)(id)
538+
}
531539
}
532540

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