compiler icon indicating copy to clipboard operation
compiler copied to clipboard

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

Open lue-bird opened this issue 2 years ago • 1 comments

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.

lue-bird avatar Oct 03 '23 20:10 lue-bird

Thanks for reporting this! To set expectations:

  • Issues are reviewed in batches, so it can take some time to get a response.
  • Ask questions in a community forum. You will get an answer quicker that way!
  • If you experience something similar, open a new issue. We like duplicates.

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

github-actions[bot] avatar Oct 03 '23 20:10 github-actions[bot]