Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler improperly detects cycles if mutually recursive functions are defined #1144

Open
edwardpeters opened this issue Feb 19, 2024 · 0 comments
Labels
task Task level project item

Comments

@edwardpeters
Copy link

edwardpeters commented Feb 19, 2024

Describe the bug
morphir-elm make will report value cycles when none exist.

To Reproduce
The following code compiles in native elm but not in morphir-elm:

countA : Int -> Int
countA x = 
    if x == 0
        then 0
        else x + countB (x-1)

countB : Int -> Int
countB x = 
    if x == 0
        then 0
        else x + countA (x-1)

The following example demonstrates the same issue, but better isolates that it is specifically mutually recursive functions that cause this issue:

type IntCons = 
    Nil
    | HeadTail Int IntCons

sum : IntCons -> Int
sum c = 
    case c of
        Nil -> 0
        HeadTail i tail -> i + redirect tail

redirect : IntCons -> Int
redirect x = sum x

Note that without the `redirect` function this is accepted.

Expected behavior
As this is not a true value cycle, the compiler should not reject it.

Desktop (please complete the following information):

  • OS: OSX
  • Version: 2.89.0

Additional context
While the example above is pointless, this is causing us an actual issue where we need a "dispatch" function that may send certain variants of a recursive type to particular handlers based on what else exists in the tree.

@edwardpeters edwardpeters added the task Task level project item label Feb 19, 2024
@edwardpeters edwardpeters changed the title Compiler improperly detects cycles Compiler improperly detects cycles if mutually recursive functions are dfined Feb 20, 2024
@edwardpeters edwardpeters changed the title Compiler improperly detects cycles if mutually recursive functions are dfined Compiler improperly detects cycles if mutually recursive functions are defined Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
task Task level project item
Projects
None yet
Development

No branches or pull requests

1 participant