diff options
Diffstat (limited to 'src/Sema.zig')
| -rw-r--r-- | src/Sema.zig | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index f9b37f5b49..3e62344a04 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -17359,17 +17359,10 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat } try sema.requireRuntimeBlock(block, src, operand_src); - if (block.wantSafety() and !dest_ty.isAnyError()) { + if (block.wantSafety() and !dest_ty.isAnyError() and sema.mod.comp.bin_file.options.use_llvm) { const err_int_inst = try block.addBitCast(Type.u16, operand); - // TODO: Output a switch instead of chained OR's. - var found_match: Air.Inst.Ref = undefined; - for (dest_ty.errorSetNames()) |dest_err_name, i| { - const dest_err_int = (try sema.mod.getErrorValue(dest_err_name)).value; - const dest_err_int_inst = try sema.addIntUnsigned(Type.u16, dest_err_int); - const next_match = try block.addBinOp(.cmp_eq, dest_err_int_inst, err_int_inst); - found_match = if (i == 0) next_match else try block.addBinOp(.bool_or, found_match, next_match); - } - try sema.addSafetyCheck(block, found_match, .invalid_error_code); + const ok = try block.addTyOp(.error_set_has_value, dest_ty, err_int_inst); + try sema.addSafetyCheck(block, ok, .invalid_error_code); } return block.addBitCast(dest_ty, operand); } |
