Elm Exactly
Results / elm /

TypeMismatchFlexibleRecordWithAnExtraFieldWhereClosedTest

Tags:elm19-compile-errorelm-spec

Checks, in A Standard Definition of Elm?:rule s-atpat-recordrule s-exp-app

Not translated into Lean for the mechanisation of the book: see why.

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
The compiler rejects passing a record that must have an `age` field to a function that takes exactly `{ name : Int }`, with a TYPE MISMATCH error.

Inside `h`, `a.age` requires `a` to have an `age` field, and `g a` requires `a` to be the closed
record `{ name : Int }`, which has no such field.

Results

elm-0.19.1

pass
Output
Compiling ...-- TYPE MISMATCH - src/TypeMismatchFlexibleRecordWithAnExtraFieldWhereClosedTest.elm

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

22|     g a
          ^
This `a` value is a:

    { b | age : a, name : Int }

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

    { name : Int }

Hint: Seems like a record field typo. Maybe age should be name?

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!

Detected problems in 1 module.

elm-0.19.2

pass
Output
Compiling ...-- TYPE MISMATCH - src/TypeMismatchFlexibleRecordWithAnExtraFieldWhereClosedTest.elm

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

22|     g a
          ^
This `a` value is a:

    { b | age : a, name : Int }

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

    { name : Int }

Hint: Seems like a record field typo. Maybe age should be name?

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!

Detected problems in 1 module.

elm-0.19.3

pass
Output
Compiling ...-- TYPE MISMATCH - src/TypeMismatchFlexibleRecordWithAnExtraFieldWhereClosedTest.elm

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

22|     g a
          ^
This `a` value is a:

    { b | age : a, name : Int }

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

    { name : Int }

Hint: Seems like a record field typo. Maybe age should be name?

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!

Detected problems in 1 module.

lamdera-1.5.0

pass
Output
Detected problems in 1 module.
-- TYPE MISMATCH - src/TypeMismatchFlexibleRecordWithAnExtraFieldWhereClosedTest.elm

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

22|     g a
          ^
This `a` value is a:

    { b | age : a, name : Int }

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

    { name : Int }

Hint: Seems like a record field typo. Maybe age should be name?

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!

Discussions

Discuss this test·Search the discussions on GitHub

Discussions are on GitHub; one about this test has [t:elm/TypeMismatchFlexibleRecordWithAnExtraFieldWhereClosedTest] in its title.

Source

The -- CHECK: lines give the expected output.

module TypeMismatchFlexibleRecordWithAnExtraFieldWhereClosedTest exposing (..)
{-| The compiler rejects passing a record that must have an `age` field to a function that takes exactly `{ name : Int }`, with a TYPE MISMATCH error.
Inside `h`, `a.age` requires `a` to have an `age` field, and `g a` requires `a` to be the closed
record `{ name : Int }`, which has no such field.
-}
-- TAGS: elm19-compile-error
-- TAGS: elm-spec, s-atpat-record, s-exp-app
-- COMPILE-ERROR: TYPE MISMATCH, flexible record with an extra field where closed
-- CHECK: -- TYPE MISMATCH -
g : { name : Int } -> Int
g r = r.name
h a =
let
z = a.age
in
g a

Lean translation

No reduced program for Lean's evaluator: the test expects a compile error, so it has no meaning to evaluate. Lean has the program as written, in source syntax, and proves what the static semantics says of it (below). See the Lean mechanisation for which tests are in Lean, and why.

Static semantics: Lean proves that the program as written is not legal, so a compiler must reject it (refuse_elm_TypeMismatchFlexibleRecordWithAnExtraFieldWhereClosedTest, in StandardElmMech/Certs/). The kernel finds a core of the program's typing constraints that has no solution, so no derivation types it (core refutation, plan step 11) (Stat.not_legal_of_coreRefutes). It holds for every derivation, with no hypothesis about principality.