CompilerIssue2274MutualRecursionTransmuteTest
Checks, in A Standard Definition of Elm?:rule sm-topdec-valuerule s-valbind-var
Not translated into Lean for the mechanisation of the book: see why.
Issue: elm/compiler#2274
The compiler rejects `eraseType : a -> b` because the unannotated mutually recursive `f` and `g` only have type `a -> b -> b`. <https://github.com/elm/compiler/issues/2274> `g` returns its second argument and `f` returns whatever `g` does, so `f () x` has the type of `x` and the annotation on `eraseType` is too general: a TYPE MISMATCH. Elm 0.19.1 infers `f : a -> b -> c` instead, accepts the program, and lets `eraseType` turn a `String` into an `Int`. The issue's own program used the library function `String.fromInt` to show the result; this version reproduces the same bug with `Debug.toString` in its place.
Results
elm-0.19.1
failcompiled, but a compile error was expected
--- compiler output ---
Success! Compiled 1 module.
CompilerIssue2274MutualRecursionTransmuteTest ───> /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm/out/CompilerIssue2274MutualRecursionTransmuteTest.js
elm-0.19.2
failcompiled, but a compile error was expected
--- compiler output ---
Success! Compiled 1 module.
CompilerIssue2274MutualRecursionTransmuteTest ───> /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm/out/CompilerIssue2274MutualRecursionTransmuteTest.js
elm-0.19.3
failcompiled, but a compile error was expected
--- compiler output ---
Success! Compiled 1 module.
CompilerIssue2274MutualRecursionTransmuteTest ───> /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm/out/CompilerIssue2274MutualRecursionTransmuteTest.js
lamdera-1.5.0
failcompiled, but a compile error was expected --- compiler output --- Success! Compiled 1 module.
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm/CompilerIssue2274MutualRecursionTransmuteTest] in its title.
Source
The -- CHECK: lines give the expected output.
module CompilerIssue2274MutualRecursionTransmuteTest exposing (main)
{-| The compiler rejects `eraseType : a -> b` because the unannotated mutually recursive `f` and `g` only have type `a -> b -> b`.
<https://github.com/elm/compiler/issues/2274>
`g` returns its second argument and `f` returns whatever `g` does, so `f () x` has the type of `x`
and the annotation on `eraseType` is too general: a TYPE MISMATCH. Elm 0.19.1 infers
`f : a -> b -> c` instead, accepts the program, and lets `eraseType` turn a `String` into an `Int`.
The issue's own program used the library function `String.fromInt` to show the result; this
version reproduces the same bug with `Debug.toString` in its place.
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, sm-topdec-value, s-valbind-var
-- COMPILE-ERROR: TYPE MISMATCH, eraseType's annotation is more general than f allows
-- CHECK-NOT: HasCallStack
-- CHECK: -- TYPE MISMATCH -
import Html exposing (text)
f x y =
g x y
g x y =
if False then
f x y
else
y
eraseType : a -> b
eraseType x =
f () x
main =
text (Debug.toString (eraseType "not an Int" + 1))
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_CompilerIssue2274MutualRecursionTransmuteTest, in StandardElmMech/Certs/). The proved inference W fails on a module of the program, and W fails only where no derivation exists (plan step 11) (Stat.not_legal_of_wRefutes). It holds for every derivation, with no hypothesis about principality.