Elm Exactly
Results / elm /

CompilerIssue2072ExtendUnitInResultCrashTest

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 pass

Issue: elm/compiler#2072

A result annotation that extends `()` as if it were a record must be rejected with an error
report, not crash the compiler.

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

`subscribed` is annotated to return `Tagged ()`, and `Tagged a` is the extensible record
`{ a | tags : List String }`, so this extends the non-record `()`. Elm 0.19.1 crashes; it should
report an error.

Results

elm-0.19.1

fail
Unexpected pattern (CHECK-NOT): CallStack
--- compiler output ---
Dependencies ready!
Compiling ...-- TYPE MISMATCH ---------- src/CompilerIssue2072ExtendUnitInResultCrashTest.elm

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

46|     t
        ^
This `t` value is a:

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): CallStack
--- compiler output ---
Dependencies ready!
Compiling ...-- TYPE MISMATCH ---------- src/CompilerIssue2072ExtendUnitInResultCrashTest.elm

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

46|     t
        ^
This `t` value is a:

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): CallStack
--- compiler output ---
Dependencies ready!
Compiling ...-- TYPE MISMATCH ---------- src/CompilerIssue2072ExtendUnitInResultCrashTest.elm

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

46|     t
        ^
This `t` value is a:

Detected problems in 1 module.
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


lamdera-1.5.0

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

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

46|     t
        ^
This `t` value is a:

    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/CompilerIssue2072ExtendUnitInResultCrashTest] in its title.

Source

The -- CHECK: lines give the expected output.

module CompilerIssue2072ExtendUnitInResultCrashTest exposing (..)
{-| A result annotation that extends `()` as if it were a record must be rejected with an error
report, not crash the compiler.
<https://github.com/elm/compiler/issues/2072>
`subscribed` is annotated to return `Tagged ()`, and `Tagged a` is the extensible record
`{ a | tags : List String }`, so this extends the non-record `()`. Elm 0.19.1 crashes; it should
report an error.
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, s-ty-con
-- COMPILE-ERROR: extending a non-record
-- CHECK: {{-- [A-Z ]+ -}}
-- CHECK-NOT: CallStack
import Html
type alias Tagged a =
{ a | tags : List String }
type alias Subscribed a =
{ a | subscriptions : List Int }
type alias Person =
Tagged (Subscribed { name : String })
type alias Tag =
Tagged {}
subscribed : Subscribed a -> Tagged ()
subscribed _ =
let
t : Tag
t =
{ tags = [ "elm" ] }
in
t
main =
let
p : Person
p =
{ name = "n", tags = [], subscriptions = [] }
in
Html.text (Debug.toString (subscribed p))

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_CompilerIssue2072ExtendUnitInResultCrashTest, 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.