unison icon indicating copy to clipboard operation
unison copied to clipboard

Parse failure if the last line in a scratch file is `use`

Open mitchellwrosen opened this issue 6 years ago • 1 comments

To reproduce, save this file:

a = ()
use .base

Error:

  /home/mitchell/unison/junk/scratch.u:1:3:
  unexpected =
      1 | a = ()

mitchellwrosen avatar Aug 08 '19 14:08 mitchellwrosen

Ah, this is because when we reorder stanzas to bring use and types to the top, we don’t introduce any virtual semis. So, if they were the last item the following stanza becomes part of it.

I.e., the parser effectively sees

use .base a = ()

This also occurs in any block, not just EOF. E.g., with

a = let
  x = 3
  x
  use .base

b = 3

the parser sees

a = let
  use .base x = 3
  x

I noticed this when updating the parser, but avoided changing it at the time, because I figured I was overlooking some aspect of the reordering, so I carefully preserved the bug 😅

sellout avatar Aug 23 '24 15:08 sellout