CompilerIssue1700InfiniteTypeFoldrLambdaHangTest
Checks, in A Standard Definition of Elm?:rule s-exp-apprule s-atexp-op
Not translated into Lean for the mechanisation of the book: see why.
Issue: elm/compiler#1700
A `foldr` lambda that conses a list onto an element (`uniq :: elem`) is rejected with an infinite-type error. <https://github.com/elm/compiler/issues/1700> Elm 0.19.1 hangs on it, its memory growing without bound, instead of reporting the error. The issue's own program used the library functions `List.foldr` and `List.member`; this version reproduces the same bug with local `foldr` and `member` of the same types in their 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/CompilerIssue1700InfiniteTypeFoldrLambdaHangTest] in its title.
Source
The -- CHECK: lines give the expected output.
module CompilerIssue1700InfiniteTypeFoldrLambdaHangTest exposing (main)
{-| A `foldr` lambda that conses a list onto an element (`uniq :: elem`) is rejected with an infinite-type error.
<https://github.com/elm/compiler/issues/1700>
Elm 0.19.1 hangs on it, its memory growing without bound, instead of reporting the error.
The issue's own program used the library functions `List.foldr` and `List.member`; this version
reproduces the same bug with local `foldr` and `member` of the same types in their place.
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, s-exp-app, s-atexp-op
-- COMPILE-ERROR: a type error, not a hang
-- CHECK: {{-- [A-Z ]+ -}}
-- CHECK-NOT: HasCallStack
import Html
foldr : (a -> b -> b) -> b -> List a -> b
foldr f acc list =
case list of
[] ->
acc
x :: rest ->
f x (foldr f acc rest)
member : a -> List a -> Bool
member x list =
case list of
[] ->
False
y :: rest ->
x == y || member x rest
listUnique : List a -> List a
listUnique lst =
foldr
(\elem uniq ->
if member elem uniq then
uniq
else
uniq :: elem
)
[]
lst
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_CompilerIssue1700InfiniteTypeFoldrLambdaHangTest, 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.