roc icon indicating copy to clipboard operation
roc copied to clipboard

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

Open austindd opened this issue 5 months ago • 1 comments

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

austindd avatar Jul 24 '25 20:07 austindd

This will be fixed in the new compiler: #beginners>Help implementing recursive type?@497774297

Anton-4 avatar Jul 25 '25 10:07 Anton-4