Skip to content

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

Open
@tnorth

Description

@tnorth

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions