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

Confusing error for wrong number of parameters in update #294

Closed mpizenberg closed 5 years ago

mpizenberg commented 5 years ago

Code with missing parameter in update:

module Main exposing (main)

main : Program () () ()
main =
    Platform.worker
        { init = \_ -> ( (), Cmd.none )
          -- should be \_ _ -> ...
        , update = \_ -> ( (), Cmd.none )
        , subscriptions = \_ -> Sub.none
        }

Error message:

Detected errors in 1 module.
-- TYPE MISMATCH ------------------------------ src/Main.elm

The 1st argument to `worker` is not what I expect:

 6|     Platform.worker
 7|>        { init = \_ -> ( (), Cmd.none )
 8|>        , update = \_ -> ( (), Cmd.none )
 9|>        , subscriptions = \_ -> Sub.none
10|>        }

This argument is a record of type:

    { init : flags -> ( (), Cmd msg1 )
    , subscriptions : () -> Sub msg1
    , update : msg1 -> ( (), Cmd msg )
    }

But `worker` needs the 1st argument to be:

    { init : flags -> ( (), Cmd msg1 )
    , subscriptions : () -> Sub msg1
    , update : msg1 -> ( (), Cmd msg1 )
    }
evancz commented 5 years ago

I believe this was fixed by https://github.com/elm/compiler/commit/a5febad184588ae79b404d22a020020408580041#diff-82d62175c52da5d84448be854f237b66. My development build is producing:

-- TYPE MISMATCH ------------------------------------------------------ temp.elm

The 1st argument to `worker` is not what I expect:

 5|     Platform.worker
 6|>        { init = \_ -> ( (), Cmd.none )
 7|>          -- should be \_ _ -> ...
 8|>        , update = \_ -> ( (), Cmd.none )
 9|>        , subscriptions = \_ -> Sub.none
10|>        }

This argument is a record of type:

    { init : flags -> ( (), Cmd msg1 )
    , subscriptions : () -> Sub msg1
    , update : msg1 -> ( (), Cmd msg )
    }

But `worker` needs the 1st argument to be:

    { init : flags -> ( (), Cmd msg1 )
    , subscriptions : () -> Sub msg1
    , update : msg1 -> () -> ( (), Cmd msg1 )
    }

Hint: It looks like it takes too few arguments. I was expecting 1 more.

So the Hint is a little weird, but the bug you are seeing is resolved. The fix should become available once Elm 0.19.1 is released!