Elm Exactly
Results / elm /

CompilerIssue2298IdentityAliasResultTest

Tags:elm19-bugelm-spec

Checks, in A Standard Definition of Elm?:rule sm-typbindrule s-ty-conrule s-valbind-var

Translated into Lean for the mechanisation of the book: see its Lean translation.

elm-0.19.1 failelm-0.19.2 failelm-0.19.3 faillamdera-1.5.0 fail

Issue: elm/compiler#2298, elm/compiler#2292

A type alias `Msg a = a` in an annotation's result is interchangeable with `a`, so `make = identity` type-checks against `a -> Msg a`.

<https://github.com/elm/compiler/issues/2298>

<https://github.com/elm/compiler/issues/2292>

The annotation means `a -> a`, and `make 7` should print 7. Elm 0.19.1 rejects the definition
(`a -> a` against `a -> Msg a`), although it accepts the alias in argument position.

Results

elm-0.19.1

fail
compile failed (exit 1):
Dependencies ready!
Compiling ...-- TYPE MISMATCH -------------- src/CompilerIssue2298IdentityAliasResultTest.elm

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

27|     identity
        ^^^^^^^^
This `identity` value is a:

    a -> a

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

    a -> Msg a

Detected problems in 1 module.

elm-0.19.2

fail
compile failed (exit 1):
Dependencies ready!
Compiling ...-- TYPE MISMATCH -------------- src/CompilerIssue2298IdentityAliasResultTest.elm

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

27|     identity
        ^^^^^^^^
This `identity` value is a:

    a -> a

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

    a -> Msg a

Detected problems in 1 module.

elm-0.19.3

fail
compile failed (exit 1):
Dependencies ready!
Compiling ...-- TYPE MISMATCH -------------- src/CompilerIssue2298IdentityAliasResultTest.elm

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

27|     identity
        ^^^^^^^^
This `identity` value is a:

    a -> a

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

    a -> Msg a

Detected problems in 1 module.

lamdera-1.5.0

fail
compile failed (exit 1):
Dependencies ready!
Detected problems in 1 module.
-- TYPE MISMATCH -------------- src/CompilerIssue2298IdentityAliasResultTest.elm

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

27|     identity
        ^^^^^^^^
This `identity` value is a:

    a -> a

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

    a -> Msg a

-- TYPE MISMATCH -------------- src/CompilerIssue2298IdentityAliasResultTest.elm

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

1| module CompilerIssue2298IdentityAliasResultTest exposing (main)
   ^
This `w3_x_c_a` value is a:

    a -> Lamdera.Wire3.Encoder

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

    Msg a -> Lamdera.Wire3.Encoder

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module CompilerIssue2298IdentityAliasResultTest exposing (main)
{-| A type alias `Msg a = a` in an annotation's result is interchangeable with `a`, so `make = identity` type-checks against `a -> Msg a`.
<https://github.com/elm/compiler/issues/2298>
<https://github.com/elm/compiler/issues/2292>
The annotation means `a -> a`, and `make 7` should print 7. Elm 0.19.1 rejects the definition
(`a -> a` against `a -> Msg a`), although it accepts the alias in argument position.
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, sm-typbind, s-ty-con, s-valbind-var
-- CHECK: make: 7
import Html exposing (text)
type alias Msg a =
a
make : a -> Msg a
make =
identity
main =
let
_ =
Debug.log "make" (make 7)
in
text "done"

Lean translation

This program is translated into Lean by the translator of the Lean mechanisation of A Standard Definition of Elm?: the program it is, its modules in the reduced syntax of Chapter 7 with every integer constant at Int or Float by number specialisation, and its CHECK lines as written (g_elm_CompilerIssue2298IdentityAliasResultTest, in StandardElmMech/Generated/Elm_CompilerIssue22.lean). Lean's evaluator runs the program by the rules of Chapters 7 and 9, and its checks become one generated theorem: some derivation of the program has a log that meets every check, or, for a test that stops at Debug.todo, the program has no meaning.

CheckExpected (CHECK)Lean evaluatorProved by
make77t_elm_CompilerIssue2298IdentityAliasResultTest
/-- tests/elm/src/CompilerIssue2298IdentityAliasResultTest.elm -/
def g_elm_CompilerIssue2298IdentityAliasResultTest : Program := {
  name := "CompilerIssue2298IdentityAliasResultTest", source := "tests/elm/src",
  exposing := (.items [.var "main"]), imports := [⟨"Html", "Html", some (.items [.var "text"])⟩],
  types := [],
  aliases := [("Msg", none)],
  defs := [
    .fn "make" [] (v "identity"),
    .fn "main" [] (letDefs [.pat pw (ap (qv "Debug" "log") [str "make", .atexp (.paren (ap (v "make") [.atexp (.scon (.intF 7))]))])] (ap (v "text") [str "done"])) ],
  checks := [
    chk .check "make: 7" .float ] }

Reading the translation: v "x" is the variable x, c "K" the constructor K, i 42 the integer 42 at Int, .scon (.intF 2) the integer 2 at Float, and str "s" a string; ap f [a, b] applies f to a and then b, and bin "+" a b is a + b. lams, caseOf, ifte, listE, tup2 and recE build lambdas, case, if, lists, pairs and records by the book's derived forms; pv, pw and pcon are variable, wildcard and constructor patterns. defs are the program's top-level definitions and locals the other declarations of main's let, placed in a let around each check; ckk label value kind exp is one check. A name with $ (incF$Float) is a copy number specialisation made.

Static semantics (Chapters 4, 5 and 9): legal_elm_CompilerIssue2298IdentityAliasResultTest states that the program as written is legal, with no hypothesis: the proved inference W gives each module a principal derivation, which meets the syntactic restrictions and the further restrictions, with a type of main Chapter 9 allows. End to end: spec_elm_CompilerIssue2298IdentityAliasResultTest states that Lean computes the reduced program above from the source (derived forms, inference, the proved checker, number specialisation, type erasure), so the theorems about it do not trust the translator's elaboration ([elab]); mean_elm_CompilerIssue2298IdentityAliasResultTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_CompilerIssue2298IdentityAliasResultTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.