Elm Exactly
Results / elm /

CompilerIssue1669InfiniteTypeArrayGetSetHangTest

Tags:elm19-bugelm-spec

Checks, in A Standard Definition of Elm?:rule s-exp-app

Not translated into Lean for the mechanisation of the book: see why.

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

Issue: elm/compiler#1669

A function whose type would be infinite, built from `get` and `set` on a local array type in a pipeline, is rejected with a type error.

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

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 `Array.get`, `Array.set`, `Maybe.map` and
`Maybe.withDefault`; this version reproduces the same bug with local definitions of the same
types in their place.

Results

elm-0.19.1

fail
compiler used more than 4096 MB of memory
Dependencies ready!
Compiling ...

elm-0.19.2

fail
compiler used more than 4096 MB of memory
Dependencies ready!
Compiling ...

elm-0.19.3

fail
compiler used more than 4096 MB of memory
Dependencies ready!
Compiling ...

lamdera-1.5.0

fail
compiler 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/CompilerIssue1669InfiniteTypeArrayGetSetHangTest] in its title.

Source

The -- CHECK: lines give the expected output.

module CompilerIssue1669InfiniteTypeArrayGetSetHangTest exposing (main)
{-| A function whose type would be infinite, built from `get` and `set` on a local array type in a pipeline, is rejected with a type error.
<https://github.com/elm/compiler/issues/1669>
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 `Array.get`, `Array.set`, `Maybe.map` and
`Maybe.withDefault`; this version reproduces the same bug with local definitions of the same
types in their place.
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, s-exp-app
-- COMPILE-ERROR: a type error, not a hang
-- CHECK: {{-- [A-Z ]+ -}}
-- CHECK-NOT: HasCallStack
import Html
type Arr a
= Arr (List a)
get : Int -> Arr a -> Maybe a
get i (Arr xs) =
case xs of
[] ->
Nothing
x :: rest ->
if i == 0 then
Just x
else
get (i - 1) (Arr rest)
set : Int -> a -> Arr a -> Arr a
set i v (Arr xs) =
case xs of
[] ->
Arr []
x :: rest ->
if i == 0 then
Arr (v :: rest)
else
let
(Arr rest2) =
set (i - 1) v (Arr rest)
in
Arr (x :: rest2)
maybeMap : (a -> b) -> Maybe a -> Maybe b
maybeMap f m =
case m of
Just v ->
Just (f v)
Nothing ->
Nothing
withDefault : a -> Maybe a -> a
withDefault d m =
case m of
Just v ->
v
Nothing ->
d
fribble x y =
get y x
|> maybeMap (set y x)
|> withDefault x
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_CompilerIssue1669InfiniteTypeArrayGetSetHangTest, 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.