Commit ede3798485

Veikka Tuominen <git@vexu.eu>
2022-09-23 15:38:27
Sema: resolve struct layout in `zirStructInit`
Closes #12911
1 parent 581df94
Changed files (3)
src
test
behavior
src/Sema.zig
@@ -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`.
test/behavior/bugs/12911.zig
@@ -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 };
+}
test/behavior.zig
@@ -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");