Skip to content

Enumerate potential cases in an EmptyCase error message

Motivation

I'm a forgetful developer, and I like to be reminded of things. Typed holes work well to remind me about what functions are in scope that might fit a given signature.

However, I'd also like this convenience when I'm writing a case expression. Suppose I have some large sum type that I've forgotten the exact names for, and I write:

doingThing roles = 
    case roles of

GHC currently just tells me that this is forbidden without an extension.

/home/matt/...... error:
    Empty list of alternatives in case expression
      Use EmptyCase to allow this
    |
240 |     case roles of
    |     ^^^^^^^^^^^^^

If I put the first case in, then it can emit a warning with the uncovered cases.

doingThing roles = 
    case roles of
        RolesPublic _ -> 
            undefined

====>

/home/matt/......hs:242:5: error: [-Wincomplete-patterns, -Werror=incomplete-patterns]
    Pattern match(es) are non-exhaustive
    In a case alternative:
        Patterns not matched:
            (RolesUnsubscribed _)
            (RolesPartner _)
            (RolesAnonymousClient _)
            (RolesAnonymousVendor _)
    |
242 |     case roles of
    |     ^

Now I can copy/paste the error text in and stub out my code, but I already have to look up one of the constructors.

Proposal

Instead of rendering the EmptyCase error, render the Pattern match(es) are non-exhaustive message. If the case expression is empty, then suggest enabling EmptyCase as a side-note.

Edited by parsonsmatt
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information