Skip to content

std.builtin.TypeInfo.Declaration.data.FnDecl.arg_names is populated inconsistently for struct declarations #13152

Closed
@vsergeev

Description

@vsergeev

Zig Version

0.9.1

Steps to Reproduce

Case 1:

fn reflect(comptime entity: anytype) void {
    @compileLog(@typeInfo(entity).Struct.decls[0].name);
    @compileLog(@typeInfo(entity).Struct.decls[0].data.Fn.arg_names);
    @compileLog(@typeInfo(entity).Struct.decls[1].name);
    @compileLog(@typeInfo(entity).Struct.decls[1].data.Fn.arg_names);
}

pub const Foo = struct {
    pub fn init(a: u32, b: u64) Foo {
        _ = a;
        _ = b;
        return Foo{};
    }

    pub fn foo(self: *Foo, c: u32) void {
        _ = self;
        _ = c;
    }
};

pub fn main() !void {
    reflect(Foo);
}

Case 2:

fn reflect(comptime entity: anytype) void {
    @compileLog(@typeInfo(entity).Struct.decls[0].name);
    @compileLog(@typeInfo(entity).Struct.decls[0].data.Fn.arg_names);
    @compileLog(@typeInfo(entity).Struct.decls[1].name);
    @compileLog(@typeInfo(entity).Struct.decls[1].data.Fn.arg_names);
}

pub const Foo = struct {
    pub fn init(a: u32, b: u64) Foo {
        reflect(@This());
        _ = a;
        _ = b;
        return Foo{};
    }

    pub fn foo(self: *Foo, c: u32) void {
        _ = self;
        _ = c;
    }
};

pub fn main() !void {
    var foo = Foo.init(1, 2);
    _ = foo;
}

Expected Behavior

Both cases:

| "init"
| []const []const u8{"a","b"}
| "foo"
| []const []const u8{"self","c"}

Actual Behavior

Case 1:

| "init"
| []const []const u8{}
| "foo"
| []const []const u8{}

Case 2:

| "init"
| []const []const u8{"a","b"}
| "foo"
| []const []const u8{}

This issue appears to be similar to the later comments in #8259, but that issue was closed in March. Unsure how the closing comment applies here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions