elm / compiler

Compiler for Elm, a functional language for reliable webapps.
https://elm-lang.org/
BSD 3-Clause "New" or "Revised" License
7.48k stars 659 forks source link

Error message from generic signature with records is inconsistent with other errors from generic signatures #2240

Open joakin opened 2 years ago

joakin commented 2 years ago

Quick Summary: Error message from generic signature with records is inconsistent with other errors from generic signatures. The error message should be similar to the one posted under Additional details

SSCCE

In the REPL:

> r1 : { x : a } -> String
| r1 r = String.concat [ r.x, "Hello" ]
|
-- TYPE MISMATCH ---------------------------------------------------------- REPL

The 2nd element of this list does not match all the previous elements:

3| r1 r = String.concat [ r.x, "Hello" ]
                               ^^^^^^^
The 2nd element is a string of type:

    String

But all the previous elements in the list are:

    a

Additional Details

A similar example without records, the error message is more useful and accurate:

> f: a -> String
| f r = String.append "Hello"
|
-- TYPE MISMATCH ---------------------------------------------------------- REPL

Something is off with the body of the `f` definition:

3| f = String.append "hello"
       ^^^^^^^^^^^^^^^^^^^^^
This `append` call produces:

    String -> String

But the type annotation on `f` says it should be:

    a -> String

Hint: Your type annotation uses type variable `a` which means ANY type of value
can flow through, but your code is saying it specifically wants a `String`
value. Maybe change your type annotation to be more specific? Maybe change the
code to be more general?
github-actions[bot] commented 2 years ago

Thanks for reporting this! To set expectations:

Finally, please be patient with the core team. They are trying their best with limited resources.