CompilerIssue2112CaseBranchInfiniteTypeHangTest
Checks, in A Standard Definition of Elm?:rule s-match
Not translated into Lean for the mechanisation of the book: see why.
Issue: elm/compiler#2112
`case` branches that could only agree through an infinite type must be rejected with a type error, not hang the compiler. <https://github.com/elm/compiler/issues/2112> In `helper`, the `InputA` branch builds lists of `Maybe (Maybe a)` and the `InputB` branch lists of `Maybe a`, so the branches agree only if `a` were `Maybe a`. Elm 0.19.1 instead hangs while its memory grows without bound, or crashes. The issue's own program used the library function `List.map`; this version reproduces the same bug with a local `map` of the same type in its place.
Results
elm-0.19.1
failcompiler used more than 4096 MB of memory Dependencies ready! Compiling ...
elm-0.19.2
failcompiler used more than 4096 MB of memory Dependencies ready! Compiling ...
elm-0.19.3
failcompiler used more than 4096 MB of memory Dependencies ready! Compiling ...
lamdera-1.5.0
failcompiler used more than 4096 MB of memory Verifying dependencies (10/10)
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm/CompilerIssue2112CaseBranchInfiniteTypeHangTest] in its title.
Source
The -- CHECK: lines give the expected output.
module CompilerIssue2112CaseBranchInfiniteTypeHangTest exposing (main)
{-| `case` branches that could only agree through an infinite type must be rejected with a type
error, not hang the compiler.
<https://github.com/elm/compiler/issues/2112>
In `helper`, the `InputA` branch builds lists of `Maybe (Maybe a)` and the `InputB` branch lists
of `Maybe a`, so the branches agree only if `a` were `Maybe a`. Elm 0.19.1 instead hangs while its
memory grows without bound, or crashes.
The issue's own program used the library function `List.map`; this version reproduces the same
bug with a local `map` of the same type in its place.
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, s-match
-- COMPILE-ERROR: a type error, not a hang
-- CHECK: {{-- [A-Z ]+ -}}
-- CHECK-NOT: HasCallStack
import Html
type Input a
= InputA (List (Maybe a))
| InputB (List (List a)) (List (List a))
map : (a -> b) -> List a -> List b
map f list =
case list of
[] ->
[]
x :: rest ->
f x :: map f rest
fn : List a -> List a -> Int
fn _ _ =
0
helper lines =
case lines of
InputA source ->
( map (\part -> [ Just part ]) source
, []
)
InputB source target ->
( map (map Just) source
, map (map Just) target
)
diff : Int -> Int
diff _ =
let
( source, target ) =
helper (InputA [])
in
fn source target
main =
Html.text ""
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_CompilerIssue2112CaseBranchInfiniteTypeHangTest, 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.