diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index edaf6850d8cf..18e10817477f 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1978,7 +1978,16 @@ object Parsers { val from = termIdentOrWildcard() if (from.name != nme.WILDCARD && in.token == ARROW) atPos(startOffset(from), in.skipToken()) { - Thicket(from, termIdentOrWildcard()) + val start = in.offset + val to = termIdentOrWildcard() + val toWithPos = + if (to.name == nme.ERROR) + // error identifiers don't consume any characters, so atPos(start)(id) wouldn't set a position. + // Some testcases would then fail in Positioned.checkPos. Set a position anyway! + atPos(start, start, in.lastOffset)(to) + else + to + Thicket(from, toWithPos) } else from } diff --git a/tests/neg/parser-stability-23.scala b/tests/neg/parser-stability-23.scala new file mode 100644 index 000000000000..b8db4d937f25 --- /dev/null +++ b/tests/neg/parser-stability-23.scala @@ -0,0 +1,3 @@ +object i0 { + import Ordering.{ implicitly => } (true: Boolean) match { case _: i1 => true } // error // error +}