Compiler: Internal compiler error if --debug and Msg variant contains (Result a {x: Array ???})

Created on 16 Nov 2018  ·  7Comments  ·  Source: elm/compiler

Elm compiler : 0.19.0
possibly related:

This error occurs under specific conditions:

~/sscce ❯❯❯ elm make src/Main.elm --debug
Success! Compiled 1 module.
elm: Map.!: given key is not an element in the map
CallStack (from HasCallStack):
  error, called at libraries/containers/Data/Map/Internal.hs:603:17 in containers-0.5.10.2:Data.Map.Internal

elm make must be run with --debug
Msg must have a variant with a Result parameter
the Result must have a parameter which is a record
the record in question must contain a field which is an Array
Here is a SSCCE with which I can reliably reproduce the issue in a fresh Elm project

module Main exposing (main)

import Array exposing (Array)
import Browser


main =
    Browser.sandbox { init = 0, update = update, view = Debug.todo "" }


type alias BadRecord =
    { x : Array Int }


type Msg
    = BadMsg (Result Int BadRecord)


update msg model =
    case msg of
        BadMsg _ ->
            model

Use case:
I first encountered this error when using the http package. I was attempting to use expectJson to decode a JSON response into a record which contained an Array. expectJson fires off a Msg, so of course I made a new Msg variant with (Result Http.Error MyRecord), and that's when I hit this error.

I can work around by substituting List for Array, as this eliminates the error

Most helpful comment

To me this happens whenever I compile with --debug and Array exists somewhere in Msg. If it helps, I've noticed it's not just Array, but also Html and Attribute. There may be others as well.

The Msg in this SSCCE could be reduced to type Msg = BadMsg (Array Int) and it would result in the same error.

All 7 comments

Yes, also seeing this locally in a large project which I'm upgrading from Elm 0.18.

I'm not using the same MsgConstructor (Result A SomeRecord) pattern specifically, but I am using records in other multi-parameter types in messages, e.g. RemoteData from here.

Moved to meta issue in https://github.com/elm/compiler/issues/1851 so I can track everything easier. Thank you for the report and nice SSCCE!

To me this happens whenever I compile with --debug and Array exists somewhere in Msg. If it helps, I've noticed it's not just Array, but also Html and Attribute. There may be others as well.

The Msg in this SSCCE could be reduced to type Msg = BadMsg (Array Int) and it would result in the same error.

Indeed, as @okkero is saying, the following code also results in the error for me:

module Main exposing (main)

import Array exposing (Array)
import Browser


main =
    Browser.sandbox { init = 0, update = update, view = Debug.todo "" }


type Msg
    = BadMsg (Array Int)


update msg model =
    case msg of
        BadMsg _ ->
            model

Curiously though, the following code does _not_ result in the error. Notice the difference in the update function:

module Main exposing (main)

import Array exposing (Array)
import Browser


main =
    Browser.sandbox { init = 0, update = update, view = Debug.todo "" }


type Msg
    = BadMsg (Array Int)


update msg model =
    case msg of
        _ ->
            model

@Munksgaard This is because Msg is no longer taken to be the message type of the application in your second example. Because it is not referred to anywhere. If you add a type annotation to update or main, you will get the error again.

Either of the following will ensure Msg is the message type of the application.
update : Msg -> a -> a
main : Program () number Msg

@Munksgaard it is worth opening a new issue with your example. Comments on closed issues can get lost :)

@okkero That makes sense, thanks for the correction :-)

@harrysarson I think I'll leave it here for now, it's close enough to the original example that it shouldn't matter much. Besides, as @okkero pointed out, my "discovery" wasn't really that interesting.

Was this page helpful?
0 / 5 - 0 ratings