unison
unison copied to clipboard
Allow empty cases
Now that we have pattern-match checking we don't have a reasonable way to handle type with no constructors.
For example if I have an empty error type that I need to handle:
type MyErrors =
handleMyErrors : MyErrors -> Text
handleMyErrors = cases
This fails to compile:
😶
I expected some patterns after a match / with or cases but I didn't find any.
4 | handleMyErrors = cases
I can't even use absurd here because it's a unique type. So the only option is "bug", but this isn't great because it means Unison won't warn me that I have unhandled cases if I add a new error case in the future.
Instead we should consider just allowing empty case statements for types with no constructors (this is what Haskell does)
Thanks for reporting, we could do this during a cooldown week if desired; otherwise feels low priority.
@tstat What would need to happen here?
I expect the pattern match coverage checker to handle empty cases fine as is. I assume that error is from the parser, so maybe all that needs changing is the parser.
Chris looked into this recently, and it seemed that the pattern coverage checker succeeds when it shouldn't, when there are no cases parsed, even when the decl in question does have cases that should be covered.