authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-24 20:50:43+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-24 21:31:02+03:00
logf49dff64c64baf8be48cc987b4ed61712afabc3d
tree62b1dc0f49b146e32fc5d2561afaae8fdd7a019c
parent1d0b729f28dd5f9341c4f4fe8ab4b25592e6834a

Sema: check one possible value earlier in `zirValidateArrayInit`

Closes #12566

2 files changed, 24 insertions(+), 13 deletions(-)

src/Sema.zig+13-13
...@@ -4071,6 +4071,19 @@ fn zirValidateArrayInit(...@@ -4071,6 +4071,19 @@ fn zirValidateArrayInit(
40714071
4072 // Determine whether the value stored to this pointer is comptime-known.4072 // Determine whether the value stored to this pointer is comptime-known.
40734073
4074 if (array_ty.isTuple()) {
4075 if (array_ty.structFieldValueComptime(i)) |opv| {
4076 element_vals[i] = opv;
4077 continue;
4078 }
4079 } else {
4080 // Array has one possible value, so value is always comptime-known
4081 if (opt_opv) |opv| {
4082 element_vals[i] = opv;
4083 continue;
4084 }
4085 }
4086
4074 const elem_ptr_air_ref = sema.inst_map.get(elem_ptr).?;4087 const elem_ptr_air_ref = sema.inst_map.get(elem_ptr).?;
4075 const elem_ptr_air_inst = Air.refToIndex(elem_ptr_air_ref).?;4088 const elem_ptr_air_inst = Air.refToIndex(elem_ptr_air_ref).?;
4076 // Find the block index of the elem_ptr so that we can look at the next4089 // Find the block index of the elem_ptr so that we can look at the next
...@@ -4087,19 +4100,6 @@ fn zirValidateArrayInit(...@@ -4087,19 +4100,6 @@ fn zirValidateArrayInit(
4087 }4100 }
4088 first_block_index = @minimum(first_block_index, block_index);4101 first_block_index = @minimum(first_block_index, block_index);
40894102
4090 if (array_ty.isTuple()) {
4091 if (array_ty.structFieldValueComptime(i)) |opv| {
4092 element_vals[i] = opv;
4093 continue;
4094 }
4095 } else {
4096 // Array has one possible value, so value is always comptime-known
4097 if (opt_opv) |opv| {
4098 element_vals[i] = opv;
4099 continue;
4100 }
4101 }
4102
4103 // If the next instructon is a store with a comptime operand, this element4103 // If the next instructon is a store with a comptime operand, this element
4104 // is comptime.4104 // is comptime.
4105 const next_air_inst = block.instructions.items[block_index + 1];4105 const next_air_inst = block.instructions.items[block_index + 1];
test/behavior/tuple.zig+11
...@@ -290,3 +290,14 @@ test "coerce tuple to tuple" {...@@ -290,3 +290,14 @@ test "coerce tuple to tuple" {
290 };290 };
291 try S.foo(.{123});291 try S.foo(.{123});
292}292}
293
294test "tuple type with void field" {
295 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
296 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
297 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
298 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
299
300 const T = std.meta.Tuple(&[_]type{void});
301 const x = T{{}};
302 try expect(@TypeOf(x[0]) == void);
303}