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

Dict.fromList has confusing error message when given List Bool as key #287

Closed Janiczek closed 5 years ago

Janiczek commented 5 years ago

https://ellie-app.com/48nbR8SGTZ8a1

module Main exposing (main)

import Dict exposing (Dict)
import Html

list : List (List Bool, Bool)
list =
    []

main =
    list
    |> Dict.fromList
    |> Debug.toString
    |> Html.text

:arrow_down:

Type Mismatch
Line 12, Column 8
This function cannot handle the argument sent through the (|>) pipe:

11|     list
12|     |> Dict.fromList
           ^^^^^^^^^^^^^
The argument is:

    List ( List Bool, Bool )

But (|>) is piping it a function that expects:

    List ( List Bool, v )

When I change the List Bool to something else (eg. String), the error goes away. This makes me think it doesn't like List Bool as a key type for the Dict - possibly something about comparable? The error message is confusing and seems unrelated though.

evancz commented 5 years ago

I fixed the root issue with https://github.com/elm/compiler/commit/545b1784695500e822c2d044b6b5ed2ab6689552, so my development build is now producing:

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

This function cannot handle the argument sent through the (|>) pipe:

 9|     list
10|     |> Dict.fromList
           ^^^^^^^^^^^^^
The argument is:

    List ( List Bool, Bool )

But (|>) is piping it to a function that expects:

    List ( comparable, v )

Hint: Only ints, floats, chars, strings, lists, and tuples are comparable.

I am going to try to do better on the hint. I think I can get it to specifically mention that Bool is not comparable, but I'm not sure!

evancz commented 5 years ago

I tried making the hint really extra specific, but I ended up needing to rewrite some code that would be a bit too risky to change this close to a release. I ended up with some logic that should improve the hints on comparable clashes, but not in cases where a comparable constraint is having trouble with a type within a list or tuple.

Anyway, thank you for reporting the error here!

Janiczek commented 5 years ago

I think this

The argument is:

    List ( List Bool, Bool )

But (|>) is piping it to a function that expects:

    List ( comparable, v )

solves the most urgent problems with the original message :) Thanks!