fmease / lushui

The reference compiler of the Lushui programming language
Apache License 2.0
7 stars 0 forks source link

Malformed expression leads to butchered error diagnostic #173

Open fmease opened 1 year ago

fmease commented 1 year ago

Source:

x=lengthy-space-filler (case 0 of
    \n => n
<-)

Stderr:

error[E010]: found line break but expected ‘)’
  ┌─ /home/fmease/programming/lushui/bad-diag-msg.lushui:2:13
  │
2 │     \n => n
<-)
  │           ⟫⟪ unexpected token

error: aborting due to previous error
fmease commented 1 year ago

It's weird: The span resolution code of SourceMap should've either returned a single structured line that doesn't contain any line breaks or it should've returned two structured lines. Here it seems like it returned a single structured line that does contain a (trailing) line break which the diagnostic formatting code obviously can't and shouldn't need to handle correctly.

It's quite possible that the parser created a diagnostic with a span that includes a trailing line break (which is highly discouraged) but the span resolver should be pretty robust and should've been able to handle that (I've extensively tested that) if my theory checks out that is.

Needs investigation.