| ... | ... | @@ -9145,6 +9145,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 9145 | 9145 | return sema.analyzeErrUnionCode(block, src, operand); |
| 9146 | 9146 | } |
| 9147 | 9147 | |
| 9148 | /// If `operand` is comptime-known, asserts that it is an error value rather than a payload value. |
| 9148 | 9149 | fn analyzeErrUnionCode(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Inst.Ref) CompileError!Air.Inst.Ref { |
| 9149 | 9150 | const pt = sema.pt; |
| 9150 | 9151 | const zcu = pt.zcu; |
| ... | ... | @@ -17599,10 +17600,16 @@ fn analyzeCmp( |
| 17599 | 17600 | return sema.cmpNumeric(block, src, lhs, rhs, op, lhs_src, rhs_src); |
| 17600 | 17601 | } |
| 17601 | 17602 | if (is_equality_cmp and lhs_ty.zigTypeTag(zcu) == .error_union and rhs_ty.zigTypeTag(zcu) == .error_set) { |
| 17603 | if (try sema.resolveDefinedValue(block, lhs_src, lhs)) |lhs_val| { |
| 17604 | if (lhs_val.errorUnionIsPayload(zcu)) return .bool_false; |
| 17605 | } |
| 17602 | 17606 | const casted_lhs = try sema.analyzeErrUnionCode(block, lhs_src, lhs); |
| 17603 | 17607 | return sema.cmpSelf(block, src, casted_lhs, rhs, op, lhs_src, rhs_src); |
| 17604 | 17608 | } |
| 17605 | 17609 | if (is_equality_cmp and lhs_ty.zigTypeTag(zcu) == .error_set and rhs_ty.zigTypeTag(zcu) == .error_union) { |
| 17610 | if (try sema.resolveDefinedValue(block, rhs_src, rhs)) |rhs_val| { |
| 17611 | if (rhs_val.errorUnionIsPayload(zcu)) return .bool_false; |
| 17612 | } |
| 17606 | 17613 | const casted_rhs = try sema.analyzeErrUnionCode(block, rhs_src, rhs); |
| 17607 | 17614 | return sema.cmpSelf(block, src, lhs, casted_rhs, op, lhs_src, rhs_src); |
| 17608 | 17615 | } |
| ... | ... | @@ -23254,7 +23261,7 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData |
| 23254 | 23261 | zcu.backendSupportsFeature(.error_set_has_value)) |
| 23255 | 23262 | { |
| 23256 | 23263 | if (dest_tag == .error_union) { |
| 23257 | | const err_code = try sema.analyzeErrUnionCode(block, operand_src, operand); |
| 23264 | const err_code = try block.addTyOp(.unwrap_errunion_err, operand_ty, operand); |
| 23258 | 23265 | const err_int = try block.addBitCast(err_int_ty, err_code); |
| 23259 | 23266 | const zero_err = try pt.intRef(try pt.errorIntType(), 0); |
| 23260 | 23267 | |