Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structs containing a pointer to array of @This() fails (struct depends on itself) #8050

Open
tnorth opened this issue Feb 22, 2021 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@tnorth
Copy link

tnorth commented Feb 22, 2021

Creating a struct containing an array of pointers to itself works.
However, creating a struct containing a pointer to an array of structs of the same type fails with the error error: struct 'Bar' depends on itself

const Foo = struct {
    child: [2]*@This(), // Array of 2 pointers to a struct Foo, works. 
};

const Bar = struct {
    child: ?*[2]@This(), // Optional pointer to an array of two struct Bar, fails.
};

pub fn main() !void {
    var foo : Foo = undefined; 
    const foo2 = Foo {.child = [2]*Foo{&foo, &foo}, };

    var bar : Bar = Bar {.child = null};
    const bar2 = Bar {.child = *[2]Bar{&bar, &bar}, };

    return;
}

In struct Bar, removing ? and using bar bar: Bar = undefined also fails with the above error.

Using zig-linux-x86_64-0.8.0-dev.1158+0aef1faa8

@Vexu Vexu added stage1 The process of building from source via WebAssembly and the C backend. bug Observed behavior contradicts documented or intended behavior labels Feb 26, 2021
@Vexu Vexu modified the milestones: 0.8.0, 0.9.0 Feb 26, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
@Vexu
Copy link
Member

Vexu commented Jan 19, 2023

Works in self-hosted when using -fstrip since the LLVM backend recurses infinitely when generating debug info for Bar.

Simple reduction from #12325 (comment)

const Foo = struct {
    ptr: *[1]Foo,
};

test {
    const x: Foo = undefined;
    _ = x;
}

@Vexu Vexu removed the stage1 The process of building from source via WebAssembly and the C backend. label Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

3 participants