Skip to content

Dependency Cycle detection of @typeInfo is order dependent #24636

@uniboi

Description

@uniboi

Zig Version

0.15.0-dev.1276+3fbdd58a8

Steps to Reproduce and Observed Behavior

Referencing types that contain cyclic types using @typeInfo will trigger the error struct 'T' depends on itself. This error will not occur if the self referential type is resolved first.

const A = struct {
    b: *B,
};

const B = struct {
    a: a: { _ = @typeInfo(A); break :a void; },
};

const C = struct {
    a: a: { _ = @typeInfo(A); break :a void; },
};

test {
    _ = @as(C, undefined); // error: struct 'main.A' depends on itself
}

test {
  _ = @as(B, undefined);
  _ = @as(C, undefined); // no error
}

Expected Behavior

Both tests should compile without errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions