Elm Exactly
Results / elm /

CompilerIssue1896ExtendCustomTypeCrashTest

Tags:elm19-bugelm-spec

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

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

Extending a custom type as if it were a record crashes the compiler while reporting the error.

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

`Model Bad` extends the non-record `Bad`. Elm 0.19.1 starts a TYPE MISMATCH report and then
crashes ("Used toErrorType on a type that is not well-formed"); it should report the error.

Results

elm-0.19.1

fail
Unexpected pattern (CHECK-NOT): not well-formed
--- compiler output ---
Dependencies ready!
Compiling ...-- TYPE MISMATCH ------------ src/CompilerIssue1896ExtendCustomTypeCrashTest.elm

Something is off with the body of the `worker` definition:

31|>    Platform.worker
32|>        { init = always ( { a = () }, Cmd.none )
33|>        , update = \_ model -> ( model, Cmd.none )
34|>        , subscriptions = always Sub.none
35|>        }

This `worker` call produces:

Detected problems in 1 module.
elm: Used toErrorType on a type that is not well-formed
CallStack (from HasCallStack):
  error, called at compiler/src/Type/Type.hs:541:21 in main:Type.Type

elm-0.19.2

fail
Unexpected pattern (CHECK-NOT): not well-formed
--- compiler output ---
Dependencies ready!
Compiling ...-- TYPE MISMATCH ------------ src/CompilerIssue1896ExtendCustomTypeCrashTest.elm

Something is off with the body of the `worker` definition:

31|>    Platform.worker
32|>        { init = always ( { a = () }, Cmd.none )
33|>        , update = \_ model -> ( model, Cmd.none )
34|>        , subscriptions = always Sub.none
35|>        }

This `worker` call produces:

Detected problems in 1 module.
elm: Used toErrorType on a type that is not well-formed
CallStack (from HasCallStack):
  error, called at compiler/src/Type/Type.hs:540:21 in elm-0.19.2-inplace-elm:Type.Type

elm-0.19.3

fail
Unexpected pattern (CHECK-NOT): not well-formed
--- compiler output ---
Compiling ...-- TYPE MISMATCH ------------ src/CompilerIssue1896ExtendCustomTypeCrashTest.elm

Something is off with the body of the `worker` definition:

31|>    Platform.worker
32|>        { init = always ( { a = () }, Cmd.none )
33|>        , update = \_ model -> ( model, Cmd.none )
34|>        , subscriptions = always Sub.none
35|>        }

This `worker` call produces:

    elm: Used toErrorType on a type that is not well-formed

Type.Type.termToErrorType (line 507)
HasCallStack backtrace:
  collectBacktraces, called at libraries/ghc-internal/src/GHC/Internal/Exception.hs:169:13 in ghc-internal:GHC.Internal.Exception
  toExceptionWithBacktrace, called at libraries/ghc-internal/src/GHC/Internal/Exception.hs:89:42 in ghc-internal:GHC.Internal.Exception
  throw, called at compiler/src/Type/Type.hs:507:22 in elm-0.19.3-inplace-elm:Type.Type


Detected problems in 1 module.

lamdera-1.5.0

fail
Unexpected pattern (CHECK-NOT): not well-formed
--- compiler output ---
Detected problems in 1 module.
-- TYPE MISMATCH ------------ src/CompilerIssue1896ExtendCustomTypeCrashTest.elm

Something is off with the body of the `worker` definition:

31|>    Platform.worker
32|>        { init = always ( { a = () }, Cmd.none )
33|>        , update = \_ model -> ( model, Cmd.none )
34|>        , subscriptions = always Sub.none
35|>        }

This `worker` call produces:

    lamdera: Crash {_module = Module "Type.Type", _name = Name "Type.Type.termToErrorType", _line = Line 1264, _message = "Used toErrorType on a type that is not well-formed"}

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module CompilerIssue1896ExtendCustomTypeCrashTest exposing (..)
{-| Extending a custom type as if it were a record crashes the compiler while reporting the error.
<https://github.com/elm/compiler/issues/1896>
`Model Bad` extends the non-record `Bad`. Elm 0.19.1 starts a TYPE MISMATCH report and then
crashes ("Used toErrorType on a type that is not well-formed"); it should report the error.
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, s-ty-con
-- COMPILE-ERROR: extending a non-record
-- CHECK: {{-- [A-Z ]+ -}}
-- CHECK-NOT: not well-formed
import Html
type alias Model record =
{ record | a : () }
type Bad
= Bad
worker : Program () (Model Bad) ()
worker =
Platform.worker
{ init = always ( { a = () }, Cmd.none )
, update = \_ model -> ( model, Cmd.none )
, subscriptions = always Sub.none
}
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_CompilerIssue1896ExtendCustomTypeCrashTest, in StandardElmMech/Certs/). Some type expression of the program (an alias, a constructor's argument, an annotation, a port) elaborates in no derivation (Stat.not_legal_of_typesFailB). It holds for every derivation, with no hypothesis about principality.