CompilerIssue2083ExtendCustomTypeFieldAccessCrashTest
Checks, in A Standard Definition of Elm?:rule s-ty-con
Not translated into Lean for the mechanisation of the book: see why.
Issue: elm/compiler#2083
Extending a custom type as if it were a record must be rejected with an error report, not
crash the compiler.
<https://github.com/elm/compiler/issues/2083>
`Article a` is the extensible record `{ a | title : String, tags : List String }`, so `Article
Preview` extends the custom type `Preview`, and `id` then reads `p.id` from it. Elm 0.19.1 crashes
("Used toErrorType on a type that is not well-formed"); it should report an error.Results
elm-0.19.1
failMissing pattern: {{-- [A-Z ]+ -}}
--- compiler output ---
Dependencies ready!
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
failMissing pattern: {{-- [A-Z ]+ -}}
--- compiler output ---
Dependencies ready!
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
failMissing pattern: {{-- [A-Z ]+ -}}
--- compiler output ---
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
failMissing pattern: {{-- [A-Z ]+ -}}
--- compiler output ---
Dependencies ready!
Detected problems in 1 module.
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/CompilerIssue2083ExtendCustomTypeFieldAccessCrashTest] in its title.
Source
The -- CHECK: lines give the expected output.
module CompilerIssue2083ExtendCustomTypeFieldAccessCrashTest exposing (..)
{-| Extending a custom type as if it were a record must be rejected with an error report, not
crash the compiler.
<https://github.com/elm/compiler/issues/2083>
`Article a` is the extensible record `{ a | title : String, tags : List String }`, so `Article
Preview` extends the custom type `Preview`, and `id` then reads `p.id` from it. Elm 0.19.1 crashes
("Used toErrorType on a type that is not well-formed"); 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: not well-formed
import Html
type alias Article a =
{ a | title : String, tags : List String }
type Preview
= Article { id : Int }
id : Article Preview -> Int
id p =
p.id
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_CompilerIssue2083ExtendCustomTypeFieldAccessCrashTest, 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.