mirror of
https://github.com/ziglang/zig.git
synced 2026-01-27 17:55:24 +00:00
In stage1, this behavior was allowed (by accident?) and also accidentally exercised by the behavior test changed in this commit. In discussion on Discord, Andrew decided this should not be allowed in stage2 since there is currently on real world reason to allow this strange edge case. I've added the compiler test to solidify that this behavior should NOT occur and updated the behavior test to the new valid semantics.
43 lines
1.2 KiB
Zig
43 lines
1.2 KiB
Zig
const std = @import("std");
|
|
const testing = std.testing;
|
|
const StructField = std.builtin.Type.StructField;
|
|
const Declaration = std.builtin.Type.Declaration;
|
|
|
|
const text =
|
|
\\f1
|
|
\\f2
|
|
\\f3
|
|
;
|
|
|
|
test "issue 6456" {
|
|
comptime {
|
|
var fields: []const StructField = &[0]StructField{};
|
|
|
|
var it = std.mem.tokenize(u8, text, "\n");
|
|
while (it.next()) |name| {
|
|
fields = fields ++ &[_]StructField{StructField{
|
|
.alignment = 0,
|
|
.name = name,
|
|
.field_type = usize,
|
|
.default_value = &@as(?usize, null),
|
|
.is_comptime = false,
|
|
}};
|
|
}
|
|
|
|
const T = @Type(.{
|
|
.Struct = .{
|
|
.layout = .Auto,
|
|
.is_tuple = false,
|
|
.fields = fields,
|
|
.decls = &[_]Declaration{},
|
|
},
|
|
});
|
|
|
|
const gen_fields = @typeInfo(T).Struct.fields;
|
|
try testing.expectEqual(3, gen_fields.len);
|
|
try testing.expectEqualStrings("f1", gen_fields[0].name);
|
|
try testing.expectEqualStrings("f2", gen_fields[1].name);
|
|
try testing.expectEqualStrings("f3", gen_fields[2].name);
|
|
}
|
|
}
|