zig
zig copied to clipboard
compiler segfault using `@Type()`
Zig Version
0.10.0-dev.3986+e323cf126
Steps to Reproduce
Here is a repro case:
const std = @import("std");
fn StructArray(comptime T: type) type {
// std.debug.assert(@alignOf(T) == 8);
const field = std.builtin.Type.StructField{
.name = "field",
.field_type = T,
.default_value = null,
.is_comptime = false,
// .alignment = 8,
.alignment = @alignOf(T),
};
return @Type(std.builtin.Type{
.Struct = .{
.layout = .Auto,
.fields = &.{field},
.decls = &.{},
.is_tuple = false,
},
});
}
const Statistics = struct {
n_samples: usize,
};
const RunStats = StructArray(Statistics);
test "StructArray" {
_ = RunStats;
}
Put this in a file repro.zig
and run zig test repro.zig
.
Expected Behavior
The test compiles and passes.
Actual Behavior
The compiler segfaults, with no helpful errors, the only output I get is Segmentation fault (core dumped)
.
Here are some additional notes:
- the test compiles and passes with
zig test -fstage1 repro.zig
- the test compiles and passes when uncommenting the assertion on line 4
- the test compiles and passes when uncommenting line 10 and commenting line 11
- changing the type of the
n_samples
field tou64
, or some other primitive type does not help. - changing the definition of
Runstats
toconst RunStats = StructArray(usize)
, or some other primitive type makes the test compile and pass