authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-11-03 16:56:11+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-11-03 22:39:13+00:00
loga95be8f0e06b528c246b7b4f6cada557568017e2
tree2506d3d8ed459ac5dc9ea0579de24a61d3cf3344
parentb197c4d79b2bf1ef64a7be0b81eb47e225a323ff

Sema: use correct error bit length when emitting error_set_has_value safety checks

Resolves: #17843

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

src/Sema.zig+2-4
......@@ -21775,11 +21775,9 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2177521775 if (dest_tag == .ErrorUnion) {
2177621776 const err_code = try sema.analyzeErrUnionCode(block, operand_src, operand);
2177721777 const err_int = try block.addBitCast(err_int_ty, err_code);
21778 const zero_u16 = Air.internedToRef(try mod.intern(.{
21779 .int = .{ .ty = .u16_type, .storage = .{ .u64 = 0 } },
21780 }));
21778 const zero_err = try mod.intRef(try mod.errorIntType(), 0);
2178121779
21782 const is_zero = try block.addBinOp(.cmp_eq, err_int, zero_u16);
21780 const is_zero = try block.addBinOp(.cmp_eq, err_int, zero_err);
2178321781 if (disjoint) {
2178421782 // Error must be zero.
2178521783 try sema.addSafetyCheck(block, src, is_zero, .invalid_error_code);