Elm Exactly
Results / elm /

TypeMismatchFlexibleRecordWhereClosedAfterAMismatchTest

Tags:elm19-compile-errorelm-spec

Checks, in A Standard Definition of Elm?:rule s-exp-apprule s-atexp-tuplerule s-atpat-record

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 tuple whose two components both disagree with the annotation, with a TYPE MISMATCH error.

`g` expects `( Int, { name : Int } )`. `h` passes `( "s", a )`, where the first component is a
`String`, and `a` is a record whose `name` is a `String`, since `a.name ++ "s"` uses it as one.

Results

elm-0.19.1

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

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

22|     g ( "s", a )
          ^^^^^^^^^^
This argument is a tuple of type:

    ( String, { a | name : String } )

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

    ( Int, { name : Int } )

Hint: Want to convert a String into an Int? Use the String.toInt function!

Detected problems in 1 module.

elm-0.19.2

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

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

22|     g ( "s", a )
          ^^^^^^^^^^
This argument is a tuple of type:

    ( String, { a | name : String } )

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

    ( Int, { name : Int } )

Hint: Want to convert a String into an Int? Use the String.toInt function!

Detected problems in 1 module.

elm-0.19.3

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

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

22|     g ( "s", a )
          ^^^^^^^^^^
This argument is a tuple of type:

    ( String, { a | name : String } )

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

    ( Int, { name : Int } )

Hint: Want to convert a String into an Int? Use the String.toInt function!

Detected problems in 1 module.

lamdera-1.5.0

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

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

22|     g ( "s", a )
          ^^^^^^^^^^
This argument is a tuple of type:

    ( String, { a | name : String } )

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

    ( Int, { name : Int } )

Hint: Want to convert a String into an Int? Use the String.toInt function!

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module TypeMismatchFlexibleRecordWhereClosedAfterAMismatchTest exposing (..)
{-| The compiler rejects passing a tuple whose two components both disagree with the annotation, with a TYPE MISMATCH error.
`g` expects `( Int, { name : Int } )`. `h` passes `( "s", a )`, where the first component is a
`String`, and `a` is a record whose `name` is a `String`, since `a.name ++ "s"` uses it as one.
-}
-- TAGS: elm19-compile-error
-- TAGS: elm-spec, s-exp-app, s-atexp-tuple, s-atpat-record
-- COMPILE-ERROR: TYPE MISMATCH, flexible record where closed after a mismatch
-- CHECK: -- TYPE MISMATCH -
g : ( Int, { name : Int } ) -> Int
g p = 0
h a =
let
z = a.name ++ "s"
in
g ( "s", 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_TypeMismatchFlexibleRecordWhereClosedAfterAMismatchTest, 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.