Sema: resolve struct layout in zirStructInit

Closes #12911
This commit is contained in:
Veikka Tuominen 2022-09-23 16:38:27 +03:00
parent 581df942e1
commit ede3798485
3 changed files with 14 additions and 2 deletions

View File

@ -15966,8 +15966,8 @@ fn zirStructInit(
const first_item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end).data;
const first_field_type_data = zir_datas[first_item.field_type].pl_node;
const first_field_type_extra = sema.code.extraData(Zir.Inst.FieldType, first_field_type_data.payload_index).data;
const unresolved_struct_type = try sema.resolveType(block, src, first_field_type_extra.container_type);
const resolved_ty = try sema.resolveTypeFields(block, src, unresolved_struct_type);
const resolved_ty = try sema.resolveType(block, src, first_field_type_extra.container_type);
try sema.resolveTypeLayout(block, src, resolved_ty);
if (resolved_ty.zigTypeTag() == .Struct) {
// This logic must be synchronized with that in `zirStructInitEmpty`.

View File

@ -93,6 +93,7 @@ test {
_ = @import("behavior/bugs/12794.zig");
_ = @import("behavior/bugs/12801-1.zig");
_ = @import("behavior/bugs/12801-2.zig");
_ = @import("behavior/bugs/12911.zig");
_ = @import("behavior/bugs/12928.zig");
_ = @import("behavior/byteswap.zig");
_ = @import("behavior/byval_arg_var.zig");

View File

@ -0,0 +1,11 @@
const builtin = @import("builtin");
const Item = struct { field: u8 };
const Thing = struct {
array: [1]Item,
};
test {
if (builtin.zig_backend == .stage1) return error.SkipZigTest;
_ = Thing{ .array = undefined };
}