Elm Exactly
Results / elm /

CompilerIssue2207MutualRecursionSecondFunctionTest

Tags:elm19-bugelm-spec

Checks, in A Standard Definition of Elm?:rule sm-topdec-valuerule sm-item-varrule dm-topdec-val

Translated into Lean for the mechanisation of the book: see its Lean translation.

elm-0.19.1 failelm-0.19.2 failelm-0.19.3 faillamdera-1.5.0 fail

Issue: elm/compiler#2207

The second of two exposed, unannotated, mutually recursive functions can be used from another
module.

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

`CompilerIssue2207Mutual` exposes `f` and `g`, which call each other and have no annotations. Elm
0.19.1 crashes when a module uses `g`, in `elm make` as in `elm repl`: "Map.!: given key is not an
element in the map". The program is valid and should print `g 3: 0`.

Results

elm-0.19.1

fail
compile failed (exit 1):
Dependencies ready!
Compiling (1)elm: Map.!: given key is not an element in the map
CallStack (from HasCallStack):
  error, called at libraries/containers/Data/Map/Internal.hs:610:17 in containers-0.5.11.0:Data.Map.Internal

-- 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
compile failed (exit 1):
Dependencies ready!
Compiling (1)elm: Map.!: given key is not an element in the map
CallStack (from HasCallStack):
  error, called at libraries/containers/containers/src/Data/Map/Internal.hs:622:17 in containers-0.6.8-b28e:Data.Map.Internal

-- 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

fail
compile failed (exit 1):
Compiling (1)
-- ERROR -----------------------------------------------------------------------

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

>   unable to find "number"
>   
>   Type.Solve.srcTypeToVar (line 554) (in module CompilerIssue2207MutualRecursionSecondFunctionTest)

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: unable to find "number"

Type.Solve.srcTypeToVar (line 554) (in module CompilerIssue2207MutualRecursionSecondFunctionTest)
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 builder/src/Reporting.hs:445:45 in elm-0.19.3-inplace-elm:Reporting


lamdera-1.5.0

fail
compile failed (exit 1):

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

lamdera-1.5.0-0.19.3-linux-x86_64-1ec0a3a092ea4c714f98404cd529abe37b0673e0 (Mon
Oct 26 11:38:05 2026 +1100) (branch:distribute)

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

>   Crash {_module = Module "Type.Type", _name = Name "Type.Type.srcTypeToVarHelp", _line = Line 548, _message = "unable to find \"number\""} (in module CompilerIssue2207MutualRecursionSecondFunctionTest)

These errors are usually pretty confusing, so start by asking around on Discord
https://dashboard.lamdera.app/docs/discuss 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.lamdera: Crash {_module = Module "Type.Type", _name = Name "Type.Type.srcTypeToVarHelp", _line = Line 548, _message = "unable to find \"number\""} (in module CompilerIssue2207MutualRecursionSecondFunctionTest)

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module CompilerIssue2207MutualRecursionSecondFunctionTest exposing (main)
{-| The second of two exposed, unannotated, mutually recursive functions can be used from another
module.
<https://github.com/elm/compiler/issues/2207>
`CompilerIssue2207Mutual` exposes `f` and `g`, which call each other and have no annotations. Elm
0.19.1 crashes when a module uses `g`, in `elm make` as in `elm repl`: "Map.!: given key is not an
element in the map". The program is valid and should print `g 3: 0`.
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, sm-topdec-value, sm-item-var, dm-topdec-val
-- CHECK: g 3: 0
import CompilerIssue2207Mutual exposing (g)
import Html exposing (text)
main =
let
_ =
Debug.log "g 3" (g 3)
in
text "done"

Lean translation

This program is translated into Lean by the translator of the Lean mechanisation of A Standard Definition of Elm?: the program it is, its modules in the reduced syntax of Chapter 7 with every integer constant at Int or Float by number specialisation, and its CHECK lines as written (g_elm_CompilerIssue2207MutualRecursionSecondFunctionTest, in StandardElmMech/Generated/Elm_CompilerIssue22.lean). Lean's evaluator runs the program by the rules of Chapters 7 and 9, and its modules' checks become one generated theorem: some derivation of the program has a log that meets every check, or, for a test that stops at Debug.todo, the program has no meaning. Its modules, in program order: tests/elm/src/CompilerIssue2207Mutual.elm, tests/elm/src/CompilerIssue2207MutualRecursionSecondFunctionTest.elm.

CheckExpected (CHECK)Lean evaluatorProved by
g 300t_elm_CompilerIssue2207MutualRecursionSecondFunctionTest
/-- tests/elm/src/CompilerIssue2207MutualRecursionSecondFunctionTest.elm, tests/elm/src/CompilerIssue2207Mutual.elm -/
def g_elm_CompilerIssue2207MutualRecursionSecondFunctionTest : Program := {
  name := "CompilerIssue2207MutualRecursionSecondFunctionTest", source := "tests/elm/src",
  exposing := (.items [.var "main"]), imports := [⟨"CompilerIssue2207Mutual", "CompilerIssue2207Mutual", some (.items [.var "g"])⟩, ⟨"Html", "Html", some (.items [.var "text"])⟩],
  types := [],
  aliases := [],
  defs := [
    .fn "main" [] (letDefs [.pat pw (ap (qv "Debug" "log") [str "g 3", .atexp (.paren (ap (v "g") [.atexp (.scon (.intF 3))]))])] (ap (v "text") [str "done"])) ],
  helpers := [
   { name := "CompilerIssue2207Mutual", path := "tests/elm/src/CompilerIssue2207Mutual.elm",
     exposing := .all, imports := [],
     types := [],
     aliases := [],
     defs := [
      .fn "f" [pv "x"] (ap (v "g") [v "x"]),
      .fn "g" [pv "x"] (ifte (bin ">" (v "x") (.atexp (.scon (.intF 0)))) (ap (v "f") [.atexp (.paren (bin "-" (v "x") (.atexp (.scon (.intF 1)))))]) (v "x")) ] } ],
  checks := [
    chk .check "g 3: 0" .float ] }

Reading the translation: v "x" is the variable x, c "K" the constructor K, i 42 the integer 42 at Int, .scon (.intF 2) the integer 2 at Float, and str "s" a string; ap f [a, b] applies f to a and then b, and bin "+" a b is a + b. lams, caseOf, ifte, listE, tup2 and recE build lambdas, case, if, lists, pairs and records by the book's derived forms; pv, pw and pcon are variable, wildcard and constructor patterns. defs are the program's top-level definitions and locals the other declarations of main's let, placed in a let around each check; ckk label value kind exp is one check. A name with $ (incF$Float) is a copy number specialisation made.

Static semantics (Chapters 4, 5 and 9): legal_elm_CompilerIssue2207MutualRecursionSecondFunctionTest states that the program as written is legal, with no hypothesis: the proved inference W gives each module a principal derivation, which meets the syntactic restrictions and the further restrictions, with a type of main Chapter 9 allows. End to end: spec_elm_CompilerIssue2207MutualRecursionSecondFunctionTest states that Lean computes the reduced program above from the source (derived forms, inference, the proved checker, number specialisation, type erasure), so the theorems about it do not trust the translator's elaboration ([elab]); mean_elm_CompilerIssue2207MutualRecursionSecondFunctionTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_CompilerIssue2207MutualRecursionSecondFunctionTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.