Skip to content

Commit 4821e2b

Browse files
authored
Merge pull request #4432 from dotty-staging/fix-positioned-error-ident-failure
Prevent position errors on Ident(nme.ERROR)
2 parents f2efe05 + 78afe8a commit 4821e2b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2018,7 +2018,16 @@ object Parsers {
20182018
val from = termIdentOrWildcard()
20192019
if (from.name != nme.WILDCARD && in.token == ARROW)
20202020
atPos(startOffset(from), in.skipToken()) {
2021-
Thicket(from, termIdentOrWildcard())
2021+
val start = in.offset
2022+
val to = termIdentOrWildcard()
2023+
val toWithPos =
2024+
if (to.name == nme.ERROR)
2025+
// error identifiers don't consume any characters, so atPos(start)(id) wouldn't set a position.
2026+
// Some testcases would then fail in Positioned.checkPos. Set a position anyway!
2027+
atPos(start, start, in.lastOffset)(to)
2028+
else
2029+
to
2030+
Thicket(from, toWithPos)
20222031
}
20232032
else from
20242033
}

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)