Skip to content

Commit cb6702f

Browse files
committed
Sema: fix missed union init OPV
1 parent 0958ea3 commit cb6702f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/Sema.zig

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5000,9 +5000,11 @@ fn validateUnionInit(
50005000
}
50015001
if (init_ref) |v| try sema.validateRuntimeValue(block, block.nodeOffset(field_ptr_data.src_node), v);
50025002

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+
}
50065008
}
50075009

50085010
fn validateStructInit(
@@ -19690,8 +19692,10 @@ fn zirStructInit(
1969019692
const base_ptr = try sema.optEuBasePtrInit(block, alloc, src);
1969119693
const field_ptr = try sema.unionFieldPtr(block, field_src, base_ptr, field_name, field_src, resolved_ty, true);
1969219694
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+
}
1969519699
return sema.makePtrConst(block, alloc);
1969619700
}
1969719701

0 commit comments

Comments
 (0)