diff --git a/elm-test-rs-tests/src/TCOMiscompilation3.elm b/elm-test-rs-tests/src/TCOMiscompilation3.elm new file mode 100644 index 00000000..56ca9ed2 --- /dev/null +++ b/elm-test-rs-tests/src/TCOMiscompilation3.elm @@ -0,0 +1,30 @@ +module TCOMiscompilation3 exposing (tcoMiscompilation3Test) + +-- From https://github.com/elm/compiler/issues/2017#issue-522563527 + +import Test exposing (Test, test) +import Expect + +windDownCrashes : Int -> (Int -> Bool) -> Bool +windDownCrashes value continuation = + if value > 0 then + windDownCrashes + (value - 1) + (\newValue -> continuation newValue) + + else + continuation 0 + +windDownDoesNotCrash : Int -> (Int -> Bool) -> Bool +windDownDoesNotCrash value continuation = + if value > 0 then + windDownDoesNotCrash + (value - 1) + continuation -- Works! + -- (\newValue -> continuation newValue) -- Crashes; max stack size exceeded + + else + continuation 0 + +tcoMiscompilation3Test = test "Another example where TCO should not cause a stack overflow in CPSed code" <| + \_ -> windDownCrashes 1 (\_ -> True) |> Expect.equal (windDownDoesNotCrash 1 (\_ -> True)) diff --git a/elm-test-rs-tests/tests/Tests.elm b/elm-test-rs-tests/tests/Tests.elm index 7e31a897..7bbfac03 100644 --- a/elm-test-rs-tests/tests/Tests.elm +++ b/elm-test-rs-tests/tests/Tests.elm @@ -7,6 +7,7 @@ import TCOMiscompilation0 exposing (tcoMiscompilation0Test) -- This causes hanging in vanilla Elm, uncomment once I have a way of failing a test after it runs for too long -- import TCOMiscompilation1 exposing (tcoMiscompilation1Test) import TCOMiscompilation2 exposing (tcoMiscompilation2Test) +import TCOMiscompilation3 exposing (tcoMiscompilation3Test) suite : Test @@ -17,4 +18,5 @@ suite = describe "TCO tests" -- This causes hanging in vanilla Elm, uncomment once I have a way of failing a test after it runs for too long -- , tcoMiscompilation1Test , tcoMiscompilation2Test + , tcoMiscompilation3Test ]