Elm Exactly
Results / elm /

CompilerIssue2105ExtensibleFoldlCrashTest

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 fail

Issue: elm/compiler#2105

Folding with a function that extends a record type parameter must produce a complete type
error report, not crash the compiler.

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

`foldl withWindow room windows` needs `Room a` and `Room { a | withWindow : () }` to be the
same type, which they are not. Elm 0.19.1 starts printing the TYPE MISMATCH report, then crashes
with "Used toErrorType on a type that is not well-formed" (Type/Type.hs:541).

The issue's own program used the library function `List.foldl`; this version reproduces the same
bug with a local `foldl` of the same type in its place.

Results

elm-0.19.1

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

The 2nd argument to `foldl` is not what I expect:

57|     foldl withWindow room windows
                         ^^^^
This `room` value is a:

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

elm-0.19.2

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

The 2nd argument to `foldl` is not what I expect:

57|     foldl withWindow room windows
                         ^^^^
This `room` value is a:

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

elm-0.19.3

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

The 2nd argument to `foldl` is not what I expect:

57|     foldl withWindow room windows
                         ^^^^
This `room` 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

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

The 2nd argument to `foldl` is not what I expect:

57|     foldl withWindow room windows
                         ^^^^
This `room` 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/CompilerIssue2105ExtensibleFoldlCrashTest] in its title.

Source

The -- CHECK: lines give the expected output.

module CompilerIssue2105ExtensibleFoldlCrashTest exposing (main, withWindows)
{-| Folding with a function that extends a record type parameter must produce a complete type
error report, not crash the compiler.
<https://github.com/elm/compiler/issues/2105>
`foldl withWindow room windows` needs `Room a` and `Room { a | withWindow : () }` to be the
same type, which they are not. Elm 0.19.1 starts printing the TYPE MISMATCH report, then crashes
with "Used toErrorType on a type that is not well-formed" (Type/Type.hs:541).
The issue's own program used the library function `List.foldl`; this version reproduces the same
bug with a local `foldl` of the same type in its place.
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, s-exp-app, s-valbind-var
-- COMPILE-ERROR: a type error, not a compiler crash
-- CHECK-NOT: HasCallStack
-- CHECK-NOT: not well-formed
-- CHECK: {{-- [A-Z ]+ -}}
-- CHECK-NOT: bypassed the normal error reporting
import Html exposing (text)
main =
text "done"
type Room a
= Room
type Window
= Window
foldl : (a -> b -> b) -> b -> List a -> b
foldl f acc list =
case list of
[] ->
acc
x :: rest ->
foldl f (f x acc) rest
withWindow : Window -> Room a -> Room { a | withWindow : () }
withWindow window room =
Room
withWindows : List Window -> Room a -> Room { a | withWindow : () }
withWindows windows room =
foldl withWindow room windows

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_CompilerIssue2105ExtensibleFoldlCrashTest, in StandardElmMech/Certs/). The kernel finds a core of the program's typing constraints that has no solution, so no derivation types it (core refutation, plan step 11) (Stat.not_legal_of_coreRefutes). It holds for every derivation, with no hypothesis about principality.