- Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Minimized code
//> using scala 3.6.2 def f(xs: List[Int]) = if x.nonEmpty then for x <- xs println(x) end if end f
Output
-- [E040] Syntax Error: /home/amarki/snips/fordone.scala:7:0 ------------------- 7 | end if |^^^ |'<-' expected, but 'end of statement' found -- [E006] Not Found Error: /home/amarki/snips/fordone.scala:4:5 ---------------- 4 | if x.nonEmpty then | ^ | Not found: x |
Expectation
The error on 6 is imprecise. In particular, I'd expect the correctly indented end if
to "contain" the parse error.
It's not clear what the three carets correspond to. I have previously seen "encoded" names produce extra carets in messages, especially when synthetic, such as a x$1
. This may be an example.
The original problem IRL was a long source file with many cascading errors due to missing definitions and subsequent errors on previous lines; the syntax error seen here was still shown first, as desired.
It looks like the precise error popped out in the middle of the cascade:
[error] 643 | if unapplied.is(CaseClass) then [error] | ^^^^ [error] | yield or do expected
Before that, it is still really wanting the <-
:
[error] 625 | warnings.result().sorta(_._2.span.point) [error] | ^ [error] | '<-' expected, but '.' found
and
[error] 638 | case _ => [error] | ^^ [error] | '<-' expected, but '=>' found
-Vprint:parser
is too late to show what the for
rewriting was trying to do:
package <empty> { def f(xs: List[Int]) = if x.nonEmpty then for x <- xs; println(x) <- _root_.scala.Predef.???; _ <- _root_.scala.Predef.??? do _root_.scala.Predef.??? }
To the untrained eye, it wants an arrow because everything looks like a generator.
The pun is that the past tense of for ... do
is fordone
.