authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-06-01 00:37:28+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-06-01 01:24:11+03:00
logf2626a3d8ecddf48a08982ca78bff03e9d39d321
tree63f38df1e2d3e9ee24f07b7280841d08e9a10806
parente49fd39463be413a66920087d77eac983a91cb71

Sema: `validate{Array,Struct}Init` shortcut only valid if base ptr is comptime known


1 files changed, 6 insertions(+), 2 deletions(-)

src/Sema.zig+6-2
......@@ -3340,7 +3340,9 @@ fn validateStructInit(
33403340 const struct_ptr = try sema.resolveInst(struct_ptr_zir_ref);
33413341 const struct_ty = sema.typeOf(struct_ptr).childType();
33423342
3343 if (is_comptime or block.is_comptime) {
3343 if ((is_comptime or block.is_comptime) and
3344 (try sema.resolveDefinedValue(block, init_src, struct_ptr)) != null)
3345 {
33443346 // In this case the only thing we need to do is evaluate the implicit
33453347 // store instructions for default field values, and report any missing fields.
33463348 // Avoid the cost of the extra machinery for detecting a comptime struct init value.
......@@ -3544,7 +3546,9 @@ fn zirValidateArrayInit(
35443546 });
35453547 }
35463548
3547 if (is_comptime or block.is_comptime) {
3549 if ((is_comptime or block.is_comptime) and
3550 (try sema.resolveDefinedValue(block, init_src, array_ptr)) != null)
3551 {
35483552 // In this case the comptime machinery will have evaluated the store instructions
35493553 // at comptime so we have almost nothing to do here. However, in case of a
35503554 // sentinel-terminated array, the sentinel will not have been populated by