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

"This argument is a record of type" with two identical types #293

Closed gilesbowkett closed 5 years ago

gilesbowkett commented 5 years ago

Hi — I'm getting an error message where Elm tells me I gave it X when it was expecting Y.

Problem is, X and Y are identical.

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

51|   Browser.element
52|>    {
53|>      init = always init,
54|>      view = view,
55|>      update = update,
56|>      subscriptions = subscriptions
57|>    }

This argument is a record of type:

    { init : flags -> ( Model, Cmd Message )
    , subscriptions : Model -> Sub Message
    , update : Message -> Model -> ( Model, Cmd Message )
    , view : Model -> Html Message
    }

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

    { init : flags -> ( Model, Cmd Message )
    , subscriptions : Model -> Sub Message
    , update : Message -> Model -> ( Model, Cmd Message )
    , view : Model -> Html Message
    }

It is actually super easy to fix the problem, but the fix has no very obvious connection to the error message, at least not for me (did a bunch of work with Elm in 2016, have only played with it here and there since).

Here's the program which triggered the error for me:

module Main exposing (..)

import Browser
import Html exposing (Html, text)

-- MODEL

type alias TermFrequency =
  {
    term : String,
    freq : Int
  }

type alias Model =
  {
  }

-- INIT

init : (List TermFrequency) -> (Model, Cmd Message)
init termFrequencies =
  (Model, Cmd.none)

-- VIEW

view : Model -> Html Message
view model =
     text "Hello Elm!"

-- MESSAGE

type Message
  = None

-- UPDATE

update : Message -> Model -> (Model, Cmd Message)
update message model =
  (model, Cmd.none)

-- SUBSCRIPTIONS

subscriptions : Model -> Sub Message
subscriptions model =
  Sub.none

-- MAIN

main : Program (List TermFrequency) Model Message
main =
  Browser.element
    {
      init = always init,
      view = view,
      update = update,
      subscriptions = subscriptions
    }

Changing init = always init to init = init gets rid of the error.

Thanks!

evancz commented 5 years ago

This was a bug that got introduced in 0.19.0 I believe. The fix was https://github.com/elm/compiler/commit/a5febad184588ae79b404d22a020020408580041, so my development build is now producing the following error:

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

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

51|   Browser.element
52|>    {
53|>      init = always init,
54|>      view = view,
55|>      update = update,
56|>      subscriptions = subscriptions
57|>    }

This argument is a record of type:

    { init : flags -> List TermFrequency -> ( Model, Cmd Message )
    , subscriptions : Model -> Sub Message
    , update : Message -> Model -> ( Model, Cmd Message )
    , view : Model -> Html Message
    }

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

    { init : flags -> ( Model, Cmd Message )
    , subscriptions : Model -> Sub Message
    , update : Message -> Model -> ( Model, Cmd Message )
    , view : Model -> Html Message
    }

Hint: It looks like it takes too many arguments. I see 1 extra.

The fix should be available once Elm 0.19.1 is released. Thank you for reporting this!

gilesbowkett commented 5 years ago

thank you for Elm!