elm / compiler

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

record extended with additional field not accepted as extensible record with record with same fields #2312

Open lue-bird opened 1 year ago

lue-bird commented 1 year ago

In this example of correct elm code

type alias Base other =
    { other | base : () }

type alias Specific other =
    Base { other | extra : () }

extra : Base (Specific other) -> ()
extra specificArgument =
    specificArgument.extra

specific : Base { extra : () }
specific =
    { base = ()
    , extra = ()
    }

specificExtra =
    extra specific

elm complains

-- TYPE MISMATCH -------------------------------------------------- src/Bug.elm

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

25|     extra specific
              ^^^^^^^^
This `specific` value is a:

    Base { extra : () }

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

    Base (Specific other)

Hint: Seems like a record field typo. Maybe base should be extra?

Hint: Can more type annotations be added? Type annotations always help me give
more specific messages, and I think they could help a lot in this case!

Any other combination of types (and no types) for extra and specific I've tried do not lead to this problem.

Additional Details

Popped up while refactoring the type properties in https://github.com/jfmengels/elm-review-simplify

https://github.com/elm/compiler/issues/2298 might be related.

github-actions[bot] commented 1 year ago

Thanks for reporting this! To set expectations:

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