| ... | @@ -14271,10 +14271,18 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -14271,10 +14271,18 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 14271 | } | 14271 | } |
| 14272 | | 14272 | |
| 14273 | try sema.requireRuntimeBlock(block, src); | 14273 | try sema.requireRuntimeBlock(block, src); |
| 14274 | if (block.wantSafety()) { | 14274 | if (block.wantSafety() and !dest_ty.isAnyError()) { |
| 14275 | // TODO | 14275 | const err_int_inst = try block.addBitCast(Type.u16, operand); |
| | 14276 | // TODO: Output a switch instead of chained OR's. |
| | 14277 | var found_match: Air.Inst.Ref = undefined; |
| | 14278 | for (dest_ty.errorSetNames()) |dest_err_name, i| { |
| | 14279 | const dest_err_int = (try sema.mod.getErrorValue(dest_err_name)).value; |
| | 14280 | const dest_err_int_inst = try sema.addIntUnsigned(Type.u16, dest_err_int); |
| | 14281 | const next_match = try block.addBinOp(.cmp_eq, dest_err_int_inst, err_int_inst); |
| | 14282 | found_match = if (i == 0) next_match else try block.addBinOp(.bool_or, found_match, next_match); |
| | 14283 | } |
| | 14284 | try sema.addSafetyCheck(block, found_match, .invalid_error_code); |
| 14276 | } | 14285 | } |
| 14277 | | | |
| 14278 | return block.addBitCast(dest_ty, operand); | 14286 | return block.addBitCast(dest_ty, operand); |
| 14279 | } | 14287 | } |
| 14280 | | 14288 | |