zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit ede379848525dce72c6e903b1895ac3e4acaf3ef (tree)
parent 581df942e1150dc2108bef1d91f0a77ba9c32e23
Author: Veikka Tuominen <git@vexu.eu>
Date:   Fri, 23 Sep 2022 16:38:27 +0300

Sema: resolve struct layout in `zirStructInit`

Closes #12911

Diffstat:
Msrc/Sema.zig | 4++--
Mtest/behavior.zig | 1+
Atest/behavior/bugs/12911.zig | 11+++++++++++
3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/Sema.zig b/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`. diff --git a/test/behavior.zig b/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"); diff --git a/test/behavior/bugs/12911.zig b/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 }; +}