unison icon indicating copy to clipboard operation
unison copied to clipboard

Allow empty cases

Open ChrisPenner opened this issue 2 years ago • 4 comments

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)

ChrisPenner avatar Mar 03 '23 20:03 ChrisPenner

Thanks for reporting, we could do this during a cooldown week if desired; otherwise feels low priority.

aryairani avatar Mar 16 '23 18:03 aryairani

@tstat What would need to happen here?

aryairani avatar Jan 02 '24 17:01 aryairani

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.

tstat avatar Jan 02 '24 18:01 tstat

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.

aryairani avatar Jul 23 '24 19:07 aryairani