Skip to content

Compiler bug - stack overflow occurs when a nominal type has more than one distinct inner recursive type. #8105

@austindd

Description

@austindd

The following code works fine:

TypeA := [
    X TypeB,
    Y TypeB,
    Nil,
]

TypeB := TypeA

But this code fails:

TypeA := [
    X TypeA,
    Y TypeB,
    Nil,
]

TypeB := TypeA

The only difference between them is that, in the second block, the X and Y tags contain different inner types (TypeA and TypeB), and in the first block, the X and Y tags contain the same inner type (TypeA).

In the first case, the compiler accepts the type with no errors. In the second case, we get the following error message:

thread '<unknown>' has overflowed its stack
fatal runtime error: stack overflow
zsh: abort      roc check

Expectation:

Both kinds of recursive data structures should be accepted by the compiler. The issue does not seem to be with mutual recursion in general, but rather this special case of multiple distinct inner recursive types.

Result:

Compiler crashes due to stack overflow when running roc check.

Notes:

Compiler release:
roc_nightly-macos_apple_silicon-2025-03-22-c47a8e9cdac

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions