Elm Exactly
Results / elm /

CompilerIssue2206RecordUpdateLetCrashTest

Tags:elm19-bug-fixelm-spec

Checks, in A Standard Definition of Elm?:rule s-atexp-update

Not translated into Lean for the mechanisation of the book: see why.

elm-0.19.1 failelm-0.19.2 failelm-0.19.3 passlamdera-1.5.0 pass

Issue: elm/compiler#2206

A type error in a record update inside a let crashes the compiler, depending on a binding's name.

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

`{ item | two = Second room }` gives `two` a `Custom a b` where `Item` needs `()`, which is a
TYPE MISMATCH. Elm 0.19.1 reports it only if the second let binding's name starts with a letter
from t to z. With the name used here it crashes instead, with "index out of bounds" and "thread
blocked indefinitely in an MVar operation". The test expects the TYPE MISMATCH report and no
crash.

Fixed in Elm 0.19.3.

Results

elm-0.19.1

fail
Unexpected pattern (CHECK-NOT): HasCallStack
--- compiler output ---
Dependencies ready!
Compiling ...elm: ./Data/Vector/Generic/Mutable.hs:703 (modify): index out of bounds (3,3)
CallStack (from HasCallStack):
  error, called at ./Data/Vector/Internal/Check.hs:87:5 in vector-0.12.0.3-c437ec060b3fdd8eecce3c5fd7ada7fe6d6f6ed56dbc08f484769fe155c657df:Data.Vector.Internal.Check

-- ERROR -----------------------------------------------------------------------

I ran into something that bypassed the normal error reporting process! I
extracted whatever information I could from the internal error:

>   thread blocked indefinitely in an MVar operation

These errors are usually pretty confusing, so start by asking around on one of
forums listed at https://elm-lang.org/community to see if anyone can get you
unstuck quickly.

-- REQUEST ---------------------------------------------------------------------

If you are feeling up to it, please try to get your code down to the smallest
version that still triggers this message. Ideally in a single Main.elm and
elm.json file.

From there open a NEW issue at https://github.com/elm/compiler/issues with your
reduced example pasted in directly. (Not a link to a repo or gist!) Do not worry
about if someone else saw something similar. More examples is better!

This kind of error is usually tied up in larger architectural choices that are
hard to change, so even when we have a couple good examples, it can take some
time to resolve in a solid way.elm: thread blocked indefinitely in an MVar operation

elm-0.19.2

fail
Unexpected pattern (CHECK-NOT): HasCallStack
--- compiler output ---
Dependencies ready!
Compiling ...elm: index out of bounds (3,3)
CallStack (from HasCallStack):
  error, called at src/Data/Vector/Internal/Check.hs:103:12 in vector-0.13.2.0-c5f5d3d65d4bbfa8d70b583d7f12b14f53d5d0d4dd455f21b70f9090be728c57:Data.Vector.Internal.Check
  checkError, called at src/Data/Vector/Internal/Check.hs:109:17 in vector-0.13.2.0-c5f5d3d65d4bbfa8d70b583d7f12b14f53d5d0d4dd455f21b70f9090be728c57:Data.Vector.Internal.Check
  check, called at src/Data/Vector/Internal/Check.hs:122:5 in vector-0.13.2.0-c5f5d3d65d4bbfa8d70b583d7f12b14f53d5d0d4dd455f21b70f9090be728c57:Data.Vector.Internal.Check
  checkIndex, called at src/Data/Vector/Generic/Mutable.hs:680:16 in vector-0.13.2.0-c5f5d3d65d4bbfa8d70b583d7f12b14f53d5d0d4dd455f21b70f9090be728c57:Data.Vector.Generic.Mutable
  modify, called at src/Data/Vector/Mutable.hs:471:10 in vector-0.13.2.0-c5f5d3d65d4bbfa8d70b583d7f12b14f53d5d0d4dd455f21b70f9090be728c57:Data.Vector.Mutable

-- ERROR -----------------------------------------------------------------------

I ran into something that bypassed the normal error reporting process! I
extracted whatever information I could from the internal error:

>   thread blocked indefinitely in an MVar operation

These errors are usually pretty confusing, so start by asking around on one of
forums listed at https://elm-lang.org/community to see if anyone can get you
unstuck quickly.

-- REQUEST ---------------------------------------------------------------------

If you are feeling up to it, please try to get your code down to the smallest
version that still triggers this message. Ideally in a single Main.elm and
elm.json file.

From there open a NEW issue at https://github.com/elm/compiler/issues with your
reduced example pasted in directly. (Not a link to a repo or gist!) Do not worry
about if someone else saw something similar. More examples is better!

This kind of error is usually tied up in larger architectural choices that are
hard to change, so even when we have a couple good examples, it can take some
time to resolve in a solid way.elm: thread blocked indefinitely in an MVar operation

elm-0.19.3

pass
Output
Compiling ...-- TYPE MISMATCH ------------- src/CompilerIssue2206RecordUpdateLetCrashTest.elm

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

52|             expectItem
53|                 { item | two = Second room }
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This argument is a record of type:

    { one : (), two : Custom a b }

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

    Item

Detected problems in 1 module.

lamdera-1.5.0

pass
Output
Detected problems in 1 module.
-- TYPE MISMATCH ------------- src/CompilerIssue2206RecordUpdateLetCrashTest.elm

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

52|             expectItem
53|                 { item | two = Second room }
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This argument is a record of type:

    { one : (), two : Custom a b }

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

    Item

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module CompilerIssue2206RecordUpdateLetCrashTest exposing (main)
{-| A type error in a record update inside a let crashes the compiler, depending on a binding's name.
<https://github.com/elm/compiler/issues/2206>
`{ item | two = Second room }` gives `two` a `Custom a b` where `Item` needs `()`, which is a
TYPE MISMATCH. Elm 0.19.1 reports it only if the second let binding's name starts with a letter
from t to z. With the name used here it crashes instead, with "index out of bounds" and "thread
blocked indefinitely in an MVar operation". The test expects the TYPE MISMATCH report and no
crash.
Fixed in Elm 0.19.3.
-}
-- TAGS: elm19-bug-fix
-- TAGS: elm-spec, s-atexp-update
-- COMPILE-ERROR: TYPE MISMATCH, not a compiler crash
-- CHECK-NOT: HasCallStack
-- CHECK: -- TYPE MISMATCH -
import Html exposing (text)
main =
text "done"
type alias Item =
{ one : ()
, two : ()
}
type Custom a b
= First a
| Second b
expectItem : Item -> ()
expectItem =
always ()
problem item room =
let
showItemHasDotOne =
item.one
crashIfFunctionNameStartsWithAtoS =
expectItem
{ item | two = Second room }
in
()

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