Commit a95be8f0e0

mlugg <mlugg@mlugg.co.uk>
2023-11-03 17:56:11
Sema: use correct error bit length when emitting error_set_has_value safety checks
Resolves: #17843
1 parent b197c4d
Changed files (1)
src/Sema.zig
@@ -21775,11 +21775,9 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
         if (dest_tag == .ErrorUnion) {
             const err_code = try sema.analyzeErrUnionCode(block, operand_src, operand);
             const err_int = try block.addBitCast(err_int_ty, err_code);
-            const zero_u16 = Air.internedToRef(try mod.intern(.{
-                .int = .{ .ty = .u16_type, .storage = .{ .u64 = 0 } },
-            }));
+            const zero_err = try mod.intRef(try mod.errorIntType(), 0);
 
-            const is_zero = try block.addBinOp(.cmp_eq, err_int, zero_u16);
+            const is_zero = try block.addBinOp(.cmp_eq, err_int, zero_err);
             if (disjoint) {
                 // Error must be zero.
                 try sema.addSafetyCheck(block, src, is_zero, .invalid_error_code);