Skip to content

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

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

Closed
vsergeev opened this issue Oct 14, 2022 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@vsergeev
Copy link

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.

@vsergeev vsergeev added the bug Observed behavior contradicts documented or intended behavior label Oct 14, 2022
@vsergeev vsergeev changed the title std.builtin.TypeInfo.Declaration.data.FnDecl.arg_names is populated inconsistently for struct members std.builtin.TypeInfo.Declaration.data.FnDecl.arg_names is populated inconsistently for struct declarations Oct 14, 2022
@vsergeev
Copy link
Author

Testing with 0.10.0-dev.4330+fb366f3cd, it seems Struct member of type info has been reorganized and that arg_names have been removed. I guess that's what the closing comment of #8259 referred to. If anybody knows of an alternate way to get the argument names, feel free to let me know 😉. Closing for now.

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

1 participant