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 hint when record field type is a list #270

Closed sentience closed 5 years ago

sentience commented 5 years ago

SSCCE: https://ellie-app.com/3gZsGj7pdnLa1

module Main exposing (main)

import Browser
import Html exposing (Html, button, div, text)

view : () -> Browser.Document ()
view model =
    { title = "Hello"
    , body = text "hello" }

main : Program () () ()
main =
    Browser.document
        { init = \_ -> ((), Cmd.none)
        , view = view
        , update = \_ _ -> ((), Cmd.none)
        , subscriptions = \_ -> Sub.none
        }

When the compiler expects a record with a field of type List a, but it gets a record with a field of type a, it displays the following hint:

Hint: Did you forget to add [] around it?

This is confusing, because it is unclear what “it” refers to. Something like this might be better:

Hint: Did you forget to add [] around the value of the the `body` field?
evancz commented 5 years ago

Ended up removing the hint in https://github.com/elm/compiler/commit/0cd361d54c3a56940ebf94882069adf1fbc4600e. Seems like it's actively confusing in some cases, and in general, probably very rarely the real problem. It is not possible to get the kind of specificity you are describing without rewriting certain aspects of the code that colors in the differences between types, and I think it'd be too risky to try that so close to a release.

Thank you for reporting this!