zig
zig copied to clipboard
Exporting declarations directly through `@field` results in a false error
Zig Version
0.11.0-dev.6840+28288dcbb
Steps to Reproduce and Observed Behavior
This snippet results in a compile failure:
comptime {
const prefix = "myprefix_";
for (@typeInfo(@This()).Struct.decls) |declaration| {
if (declaration.is_pub) {
@export(@field(@This(), declaration.name), .{ .name = prefix ++ declaration.name });
}
}
}
pub fn Test() callconv(.C) void {}
The error being:
test.zig:8:21: error: symbol to export must identify a declaration
@export(@field(@This(), declaration.name), .{ .name = prefix ++ declaration.name });
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For the record, introducing an intermediate variable results in a compilation success:
comptime {
const prefix = "myprefix_";
for (@typeInfo(@This()).Struct.decls) |declaration| {
if (declaration.is_pub) {
const test_decl = @field(@This(), declaration.name);
@export(test_decl, .{ .name = prefix ++ declaration.name });
}
}
}
pub fn Test() callconv(.C) void {}
Expected Behavior
The above snippet to successfully compile without an error - correctly exporting the declaration.