zig

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

commit f49dff64c64baf8be48cc987b4ed61712afabc3d (tree)
parent 1d0b729f28dd5f9341c4f4fe8ab4b25592e6834a
Author: Veikka Tuominen <git@vexu.eu>
Date:   Wed, 24 Aug 2022 20:50:43 +0300

Sema: check one possible value earlier in `zirValidateArrayInit`

Closes #12566

Diffstat:
Msrc/Sema.zig | 26+++++++++++++-------------
Mtest/behavior/tuple.zig | 11+++++++++++
2 files changed, 24 insertions(+), 13 deletions(-)

diff --git 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 @@ -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); +}