CompilerIssue2019AliasOfTypeVariableTest
Checks, in A Standard Definition of Elm?:rule sm-typbindrule s-ty-con
Translated into Lean for the mechanisation of the book: see its Lean translation.
Issue: elm/compiler#2019
An alias `MyType k = k` is not interchangeable with `k` in a result position.
<https://github.com/elm/compiler/issues/2019>
`MyType k` is just `k`, and `MyType k -> k` is accepted, but Elm 0.19.1 rejects `k -> MyType k`
("This `x` value is a: k ... should be: MyType k"). It should compile.Results
elm-0.19.1
failcompile failed (exit 1):
Compiling ...-- TYPE MISMATCH -------------- src/CompilerIssue2019AliasOfTypeVariableTest.elm
Something is off with the body of the `testFailure1` definition:
25| x
^
This `x` value is a:
k
But the type annotation on `testFailure1` says it should be:
MyType k
-- TYPE MISMATCH -------------- src/CompilerIssue2019AliasOfTypeVariableTest.elm
I need both sides of (==) to be the same type:
30| a == b
^^^^^^
The left side of (==) is:
MyType k
But the right side is:
k
Different types can never be equal though! Which side is messed up?
Detected problems in 1 module.
elm-0.19.2
failcompile failed (exit 1):
Dependencies ready!
Compiling ...-- TYPE MISMATCH -------------- src/CompilerIssue2019AliasOfTypeVariableTest.elm
Something is off with the body of the `testFailure1` definition:
25| x
^
This `x` value is a:
k
But the type annotation on `testFailure1` says it should be:
MyType k
-- TYPE MISMATCH -------------- src/CompilerIssue2019AliasOfTypeVariableTest.elm
I need both sides of (==) to be the same type:
30| a == b
^^^^^^
The left side of (==) is:
MyType k
But the right side is:
k
Different types can never be equal though! Which side is messed up?
Detected problems in 1 module.
elm-0.19.3
failcompile failed (exit 1):
Compiling ...-- TYPE MISMATCH -------------- src/CompilerIssue2019AliasOfTypeVariableTest.elm
Something is off with the body of the `testFailure1` definition:
25| x
^
This `x` value is a:
k
But the type annotation on `testFailure1` says it should be:
MyType k
-- TYPE MISMATCH -------------- src/CompilerIssue2019AliasOfTypeVariableTest.elm
I need both sides of (==) to be the same type:
30| a == b
^^^^^^
The left side of (==) is:
MyType k
But the right side is:
k
Different types can never be equal though! Which side is messed up?
Detected problems in 1 module.
lamdera-1.5.0
failcompile failed (exit 1):
Detected problems in 1 module.
-- TYPE MISMATCH -------------- src/CompilerIssue2019AliasOfTypeVariableTest.elm
Something is off with the body of the `testFailure1` definition:
25| x
^
This `x` value is a:
k
But the type annotation on `testFailure1` says it should be:
MyType k
-- TYPE MISMATCH -------------- src/CompilerIssue2019AliasOfTypeVariableTest.elm
I need both sides of (==) to be the same type:
30| a == b
^^^^^^
The left side of (==) is:
MyType k
But the right side is:
k
Different types can never be equal though! Which side is messed up?
-- TYPE MISMATCH -------------- src/CompilerIssue2019AliasOfTypeVariableTest.elm
Something is off with the body of the `w3_encode_MyType` definition:
1| module CompilerIssue2019AliasOfTypeVariableTest exposing (..)
^
This `w3_x_c_k` value is a:
k -> Lamdera.Wire3.Encoder
But the type annotation on `w3_encode_MyType` says it should be:
MyType k -> Lamdera.Wire3.Encoder
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm/CompilerIssue2019AliasOfTypeVariableTest] in its title.
Source
The -- CHECK: lines give the expected output.
module CompilerIssue2019AliasOfTypeVariableTest exposing (..)
{-| An alias `MyType k = k` is not interchangeable with `k` in a result position.
<https://github.com/elm/compiler/issues/2019>
`MyType k` is just `k`, and `MyType k -> k` is accepted, but Elm 0.19.1 rejects `k -> MyType k`
("This `x` value is a: k ... should be: MyType k"). It should compile.
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, sm-typbind, s-ty-con
-- CHECK: test: 1
import Html exposing (text)
type alias MyType k =
k
testFailure1 : k -> MyType k
testFailure1 x =
x
testFailure2 : MyType k -> k -> Bool
testFailure2 a b =
a == b
main =
let
_ =
Debug.log "test" (testFailure1 1)
_ =
Debug.log "equal" (testFailure2 1 1)
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_CompilerIssue2019AliasOfTypeVariableTest, in StandardElmMech/Generated/Elm_CombinatorSP.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.
| Check | Expected (CHECK) | Lean evaluator | Proved by |
|---|---|---|---|
test | 1 | 1 | t_elm_CompilerIssue2019AliasOfTypeVariableTest |
/-- tests/elm/src/CompilerIssue2019AliasOfTypeVariableTest.elm -/
def g_elm_CompilerIssue2019AliasOfTypeVariableTest : Program := {
name := "CompilerIssue2019AliasOfTypeVariableTest", source := "tests/elm/src",
exposing := .all, imports := [⟨"Html", "Html", some (.items [.var "text"])⟩],
types := [],
aliases := [("MyType", none)],
defs := [
.fn "testFailure1" [pv "x"] (v "x"),
.fn "testFailure2" [pv "a", pv "b"] (bin "==" (v "a") (v "b")),
.fn "main" [] (letDefs [.pat pw (ap (qv "Debug" "log") [str "test", .atexp (.paren (ap (v "testFailure1") [.atexp (.scon (.intF 1))]))]), .pat pw (ap (qv "Debug" "log") [str "equal", .atexp (.paren (ap (v "testFailure2") [.atexp (.scon (.intF 1)), .atexp (.scon (.intF 1))]))])] (ap (v "text") [str "done"])) ],
checks := [
chk .check "test: 1" .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_CompilerIssue2019AliasOfTypeVariableTest 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_CompilerIssue2019AliasOfTypeVariableTest 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_CompilerIssue2019AliasOfTypeVariableTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_CompilerIssue2019AliasOfTypeVariableTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.