Elm Exactly
Results / elm /

CompilerIssue2108IfBranchExtensibleRecordHangTest

Tags:elm19-bugelm-spec

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

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 pass

Issue: elm/compiler#2108

`if` branches of incompatible extensible-record function types must be rejected with a type
error, not hang the compiler.

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

One branch is `changesTypeVariable`, from `Thing { b | something : () }` to
`Thing { b | somethingElse : () }`; the other is `identity`, which needs those two types to be
equal. Elm 0.19.1 instead hangs while its memory grows without bound, or crashes.

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

pass
Output
Dependencies ready!
Detected problems in 1 module.
-- TYPE MISMATCH ----- src/CompilerIssue2108IfBranchExtensibleRecordHangTest.elm

The 2nd branch of this `if` does not match all the previous branches:

31|     if True then
32|         changesTypeVariable
33| 
34|     else
35|         identity
            ^^^^^^^^
This `identity` value is a:

    Thing { b | something : () } -> Thing { b | something : () }

But all the previous branches result in:

    Thing { b | something : () } -> Thing { b | somethingElse : () }

Hint: All branches in an `if` must produce the same type of values. This way, no
matter which branch we take, the result is always a consistent shape. Read
<https://elm-lang.org/0.19.3/custom-types> to learn how to “mix” types.

Discussions

Discuss this test·Search the discussions on GitHub

Discussions are on GitHub; one about this test has [t:elm/CompilerIssue2108IfBranchExtensibleRecordHangTest] in its title.

Source

The -- CHECK: lines give the expected output.

module CompilerIssue2108IfBranchExtensibleRecordHangTest exposing (main)
{-| `if` branches of incompatible extensible-record function types must be rejected with a type
error, not hang the compiler.
<https://github.com/elm/compiler/issues/2108>
One branch is `changesTypeVariable`, from `Thing { b | something : () }` to
`Thing { b | somethingElse : () }`; the other is `identity`, which needs those two types to be
equal. Elm 0.19.1 instead hangs while its memory grows without bound, or crashes.
-}
-- 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 Thing b
= Thing
changesTypeVariable : Thing { b | something : () } -> Thing { b | somethingElse : () }
changesTypeVariable _ =
Thing
foo =
if True then
changesTypeVariable
else
identity
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_CompilerIssue2108IfBranchExtensibleRecordHangTest, 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.