From f49dff64c64baf8be48cc987b4ed61712afabc3d Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Wed, 24 Aug 2022 20:50:43 +0300 Subject: [PATCH] Sema: check one possible value earlier in `zirValidateArrayInit` Closes #12566 --- src/Sema.zig | 26 +++++++++++++------------- test/behavior/tuple.zig | 11 +++++++++++ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/Sema.zig b/src/Sema.zig index 4e1b885486..22aa26f737 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -4071,6 +4071,19 @@ fn zirValidateArrayInit( // Determine whether the value stored to this pointer is comptime-known. + if (array_ty.isTuple()) { + if (array_ty.structFieldValueComptime(i)) |opv| { + element_vals[i] = opv; + continue; + } + } else { + // Array has one possible value, so value is always comptime-known + if (opt_opv) |opv| { + element_vals[i] = opv; + continue; + } + } + const elem_ptr_air_ref = sema.inst_map.get(elem_ptr).?; const elem_ptr_air_inst = Air.refToIndex(elem_ptr_air_ref).?; // Find the block index of the elem_ptr so that we can look at the next @@ -4087,19 +4100,6 @@ fn zirValidateArrayInit( } first_block_index = @minimum(first_block_index, block_index); - if (array_ty.isTuple()) { - if (array_ty.structFieldValueComptime(i)) |opv| { - element_vals[i] = opv; - continue; - } - } else { - // Array has one possible value, so value is always comptime-known - if (opt_opv) |opv| { - element_vals[i] = opv; - continue; - } - } - // If the next instructon is a store with a comptime operand, this element // is comptime. const next_air_inst = block.instructions.items[block_index + 1]; diff --git a/test/behavior/tuple.zig b/test/behavior/tuple.zig index 14297bd61c..971e52a0b5 100644 --- a/test/behavior/tuple.zig +++ b/test/behavior/tuple.zig @@ -290,3 +290,14 @@ test "coerce tuple to tuple" { }; try S.foo(.{123}); } + +test "tuple type with void field" { + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO + + const T = std.meta.Tuple(&[_]type{void}); + const x = T{{}}; + try expect(@TypeOf(x[0]) == void); +}