noir icon indicating copy to clipboard operation
noir copied to clipboard

Type alias referring to itself crashes the compiler

Open asterite opened this issue 9 months ago • 1 comments

Aim

Given this code:

pub type X = X;

fn main() {
    let x: X = 1;
}

Expected Behavior

It should not compile, saying that a cycle was detected while solving X.

Bug

The compiler gives a stack overflow.

To Reproduce

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

None

Blocker Context

No response

Nargo Version

No response

NoirJS Version

No response

Proving Backend Tooling & Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

asterite avatar May 15 '25 15:05 asterite

We have an existing check for cycles which hopefully covers type aliases as well and would thus issue an error for this. I'm guessing we need to prune this infinite type (e.g. replacing the rhs with Type::Error instead) since we're panicking before we can issue that error.

(If we don't already issue the error we should add a new DependencyId for type aliases and handle it in the dependency graph like we do with e.g. struct types)

jfecher avatar Jun 26 '25 18:06 jfecher