@@ -5000,9 +5000,11 @@ fn validateUnionInit(
5000
5000
}
5001
5001
if (init_ref) |v| try sema.validateRuntimeValue(block, block.nodeOffset(field_ptr_data.src_node), v);
5002
5002
5003
- const new_tag = Air.internedToRef(tag_val.toIntern());
5004
- const set_tag_inst = try block.addBinOp(.set_union_tag, union_ptr, new_tag);
5005
- try sema.checkComptimeKnownStore(block, set_tag_inst, LazySrcLoc.unneeded); // `unneeded` since this isn't a "proper" store
5003
+ if ((try sema.typeHasOnePossibleValue(tag_ty)) == null) {
5004
+ const new_tag = Air.internedToRef(tag_val.toIntern());
5005
+ const set_tag_inst = try block.addBinOp(.set_union_tag, union_ptr, new_tag);
5006
+ try sema.checkComptimeKnownStore(block, set_tag_inst, LazySrcLoc.unneeded); // `unneeded` since this isn't a "proper" store
5007
+ }
5006
5008
}
5007
5009
5008
5010
fn validateStructInit(
@@ -19690,8 +19692,10 @@ fn zirStructInit(
19690
19692
const base_ptr = try sema.optEuBasePtrInit(block, alloc, src);
19691
19693
const field_ptr = try sema.unionFieldPtr(block, field_src, base_ptr, field_name, field_src, resolved_ty, true);
19692
19694
try sema.storePtr(block, src, field_ptr, init_inst);
19693
- const new_tag = Air.internedToRef(tag_val.toIntern());
19694
- _ = try block.addBinOp(.set_union_tag, base_ptr, new_tag);
19695
+ if ((try sema.typeHasOnePossibleValue(tag_ty)) == null) {
19696
+ const new_tag = Air.internedToRef(tag_val.toIntern());
19697
+ _ = try block.addBinOp(.set_union_tag, base_ptr, new_tag);
19698
+ }
19695
19699
return sema.makePtrConst(block, alloc);
19696
19700
}
19697
19701
0 commit comments