Skip to content

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

@edwardpeters

Description

@edwardpeters

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    taskTask level project item

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions