Elm Exactly
Results / elm-error-catalogue /

ErrorMessagesIssue322LetRecursiveRecordLambdaTest

Tags:elm19-bugerror-message

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

Issue: elm/error-message-catalog#322

A `let`-bound record whose field is a lambda that refers back to the record (through
another lambda) is rejected as an infinite loop, although the recursion is well founded.

<https://github.com/elm/error-message-catalog/issues/322>

Elm 0.19.1 reports BAD RECURSION ("The `func` value is defined directly in terms of itself")
for the `let` version. The recursion goes through a lambda, so it is well founded: the program
should compile and print 120.

Results

elm-0.19.1

fail
compile failed (exit 1):
Compiling ...-- CYCLIC VALUE ------ src/ErrorMessagesIssue322LetRecursiveRecordLambdaTest.elm

The `func` value is defined directly in terms of itself, causing an infinite
loop.

26|         func =
            ^^^^
Are you are trying to mutate a variable? Elm does not have mutation, so when I
see func defined in terms of func, I treat it as a recursive definition. Try
giving the new value a new name!

Maybe you DO want a recursive value? To define func we need to know what func
is, so let’s expand it. Wait, but now we need to know what func is, so let’s
expand it... This will keep going infinitely!

Hint: The root problem is often a typo in some variable name, but I recommend
reading <https://elm-lang.org/0.19.1/bad-recursion> for more detailed advice,
especially if you actually do need a recursive value.

Detected problems in 1 module.

elm-0.19.2

fail
compile failed (exit 1):
Compiling ...-- CYCLIC VALUE ------ src/ErrorMessagesIssue322LetRecursiveRecordLambdaTest.elm

The `func` value is defined directly in terms of itself, causing an infinite
loop.

26|         func =
            ^^^^
Are you trying to mutate a variable? Elm does not have mutation, so when I see
func defined in terms of func, I treat it as a recursive definition. Try giving
the new value a new name!

Maybe you DO want a recursive value? To define func we need to know what func
is, so let’s expand it. Wait, but now we need to know what func is, so let’s
expand it... This will keep going infinitely!

Hint: The root problem is often a typo in some variable name, but I recommend
reading <https://elm-lang.org/0.19.2/bad-recursion> for more detailed advice,
especially if you actually do need a recursive value.

Detected problems in 1 module.

elm-0.19.3

fail
compiler killed by SIGSEGV
Dependencies ready!
Compiling ...-- CYCLIC VALUE ------ src/ErrorMessagesIssue322LetRecursiveRecordLambdaTest.elm

lamdera-1.5.0

fail
compile failed (exit 1):
Detected problems in 1 module.
-- CYCLIC VALUE ------ src/ErrorMessagesIssue322LetRecursiveRecordLambdaTest.elm

lamdera: Crash {_module = Module "Graph", _name = Name "Graph.withMinimalCycle", _line = Line 273, _message = "bug in RootSelector when calculating minimal cycle"}

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module ErrorMessagesIssue322LetRecursiveRecordLambdaTest exposing (main)
{-| A `let`-bound record whose field is a lambda that refers back to the record (through
another lambda) is rejected as an infinite loop, although the recursion is well founded.
<https://github.com/elm/error-message-catalog/issues/322>
Elm 0.19.1 reports BAD RECURSION ("The `func` value is defined directly in terms of itself")
for the `let` version. The recursion goes through a lambda, so it is well founded: the program
should compile and print 120.
-}
-- TAGS: elm19-bug, error-message
-- CHECK: factorial 5: 120
import Html exposing (text)
factorial : Int -> Int
factorial num =
let
eval f x =
f () x
func =
{ f =
\n ->
if n == 0 then
1
else
n * eval (\_ -> func.f) (n - 1)
}
in
func.f num
main =
let
_ =
Debug.log "factorial 5" (factorial 5)
in
text "done"