Confusing error message for missing `else` clause in if/then/else statements
#1,904 创建于 2021年5月4日
描述
If you are a new user of Unison, you might - in error, terminate your if/then/else clause with a "todo" like so if not (startsWith t rem) then Left (Expected t) todo "WIP" from the handler snippet included below. This produces the following error message:
I don't know about any ability constructor named Parse.take. Maybe make sure it's correctly
spelled and that you've imported it:
82 | {Parse.take n -> resume} ->
I don't know about any data constructor named Parse.take. Maybe make sure it's correctly spelled
and that you've imported it:
82 | {Parse.take n -> resume} ->
Or, to reduce the problem further, in a scratch file you might just forgetfully leave out the else clause altogether
val myWip = if true then "HI"
nextVal = 4
Which will produce the error:
/Users/rebeccamark/Unison/my-unison-work/parser.u:18:9:
unexpected =
18 | nextVal = 4
If possible, it might be nice if the error message mentioned something about the missing else statement as this may be a common slip of the hand.
For reference, the original code that generated the Parse.take error message is below:
Parse.run : '{Parse err} a -> Text -> Either err a
Parse.run p rem =
h : Text -> Position -> Request {Parse err} a -> Either (Parse.Error err) a
h rem pos = cases
{Parse.take n -> resume} ->
a = Text.take n rem
handle resume a with h (drop n rem)
{Parse.skip n -> resume} ->
handle resume () with h (drop n rem)
{Parse.text t -> resume} ->
if not (startsWith t rem) then Left (Expected t) todo "WIP"
handle !p with h rem (Position 0)
My unison version is a trunk version that is a few days old: devel/M1l-1068-gb0dd6e549 so I'm happy to re-pull and re-test if need be.