elm / error-message-catalog

A catalog of broken Elm programs / data to improve error messages
BSD 3-Clause "New" or "Revised" License
173 stars 17 forks source link

Error message not helping when pattern matching `Set.empty` in case expression #262

Open digitalsatori opened 6 years ago

digitalsatori commented 6 years ago

The following code:

printUser users =
    case users of
        Set.empty ->
            text "Empty"
        _ ->
            text users

caused the syntax error below which is confusing:

-- SYNTAX PROBLEM --------------------------------------------------------------

I ran into something unexpected when parsing your code!

6|         Set.empty ->
               ^
I am looking for one of the following things:

    an upper case name

I will suggest @jessta 's answer to my question in the slack, which is much clearer and helpful:

The pattern in case..of need to be literals, they can't be functions or variables. Set.empty is a function.

You probably want to use a if..then..else and Set.isEmpty, eg. if Set.isEmpty users then text "empty" else text users