Elm Exactly
Results / elm /

CompilerIssue1691ContradictoryExtensibleRecordHangTest

Tags:elm19-bugelm-spec

Checks, in A Standard Definition of Elm?:rule s-exp-apprule s-valbind-var

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#1691

A point-free definition whose extensible-record annotations contradict each other is rejected with a type error.

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

`combineAB` passes `Just` where `combineMaybeAB` needs a function from `PartialRecordA a` to
`Maybe (PartialRecordB a)`, which would make `a` contain itself.

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 function `Maybe.map` in `fullRecord`; this version
reproduces the same bug with a `case` on the `Maybe` in its 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

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

The 1st argument to `combineMaybeAB` is not what I expect:

60|     combineMaybeAB Just
                       ^^^^
This `Just` value is a:

    PartialRecordA a -> Maybe (PartialRecordA a)

But `combineMaybeAB` needs the 1st argument to be:

    PartialRecordA a -> Maybe { a | fieldB : String }

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module CompilerIssue1691ContradictoryExtensibleRecordHangTest exposing (main)
{-| A point-free definition whose extensible-record annotations contradict each other is rejected with a type error.
<https://github.com/elm/compiler/issues/1691>
`combineAB` passes `Just` where `combineMaybeAB` needs a function from `PartialRecordA a` to
`Maybe (PartialRecordB a)`, which would make `a` contain itself.
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 function `Maybe.map` in `fullRecord`; this version
reproduces the same bug with a `case` on the `Maybe` in its place.
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, s-exp-app, s-valbind-var
-- COMPILE-ERROR: a type error, not a hang
-- CHECK: {{-- [A-Z ]+ -}}
-- CHECK-NOT: HasCallStack
import Html
type alias FullRecord =
{ fieldA : String
, fieldB : Maybe String
}
type alias PartialRecordA a =
{ a | fieldA : String }
type alias PartialRecordB a =
{ a | fieldB : String }
fullRecord : PartialRecordA a -> Maybe (PartialRecordB b) -> FullRecord
fullRecord partialRecordA partialRecordB =
{ fieldA = partialRecordA.fieldA
, fieldB =
case partialRecordB of
Just r ->
Just r.fieldB
Nothing ->
Nothing
}
combineA : PartialRecordA a -> FullRecord
combineA =
combineMaybeAB (always Nothing)
combineAB : PartialRecordA (PartialRecordB a) -> FullRecord
combineAB =
combineMaybeAB Just
combineMaybeAB : (PartialRecordA a -> Maybe (PartialRecordB a)) -> PartialRecordA a -> FullRecord
combineMaybeAB partialSelectorB partialRecordA =
fullRecord partialRecordA (partialSelectorB partialRecordA)
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_CompilerIssue1691ContradictoryExtensibleRecordHangTest, 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.