Skip to content

Recursive type causes a stack overflow at compile time when using == #9633

@ageron

Description

@ageron

This issue may be related to #9632.

The following code causes a stack overflow at compile time:

BinarySearchTree := [Nil, Node({ value : U64, left : BinarySearchTree, right : BinarySearchTree })]

tree : U64 -> BinarySearchTree
tree = |v| {
    Node({
        left: Nil,
        right: Nil,
        value: v
    })
}

main! = |_args| {
    expected = Node({
        left: Nil,
        right: Nil,
        value: 123
    })
    result = tree(123) == expected
    echo!(Str.inspect(result))
    Ok({})
}

The message is:

The Roc compiler overflowed its stack memory and had to exit.

Interestingly, if I comment out the type spec of the tree function, then the problem disappears. Also, the code works if I don't use ==.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions