| ... | ... | @@ -20787,14 +20787,14 @@ fn cmpNumeric( |
| 20787 | 20787 | sema: *Sema, |
| 20788 | 20788 | block: *Block, |
| 20789 | 20789 | src: LazySrcLoc, |
| 20790 | | lhs: Air.Inst.Ref, |
| 20791 | | rhs: Air.Inst.Ref, |
| 20790 | uncasted_lhs: Air.Inst.Ref, |
| 20791 | uncasted_rhs: Air.Inst.Ref, |
| 20792 | 20792 | op: std.math.CompareOperator, |
| 20793 | 20793 | lhs_src: LazySrcLoc, |
| 20794 | 20794 | rhs_src: LazySrcLoc, |
| 20795 | 20795 | ) CompileError!Air.Inst.Ref { |
| 20796 | | const lhs_ty = sema.typeOf(lhs); |
| 20797 | | const rhs_ty = sema.typeOf(rhs); |
| 20796 | const lhs_ty = sema.typeOf(uncasted_lhs); |
| 20797 | const rhs_ty = sema.typeOf(uncasted_rhs); |
| 20798 | 20798 | |
| 20799 | 20799 | assert(lhs_ty.isNumeric()); |
| 20800 | 20800 | assert(rhs_ty.isNumeric()); |
| ... | ... | @@ -20803,6 +20803,19 @@ fn cmpNumeric( |
| 20803 | 20803 | const rhs_ty_tag = rhs_ty.zigTypeTag(); |
| 20804 | 20804 | const target = sema.mod.getTarget(); |
| 20805 | 20805 | |
| 20806 | // One exception to heterogeneous comparison: comptime_float needs to |
| 20807 | // coerce to fixed-width float. |
| 20808 | |
| 20809 | const lhs = if (lhs_ty_tag == .ComptimeFloat and rhs_ty_tag == .Float) |
| 20810 | try sema.coerce(block, rhs_ty, uncasted_lhs, lhs_src) |
| 20811 | else |
| 20812 | uncasted_lhs; |
| 20813 | |
| 20814 | const rhs = if (lhs_ty_tag == .Float and rhs_ty_tag == .ComptimeFloat) |
| 20815 | try sema.coerce(block, lhs_ty, uncasted_rhs, rhs_src) |
| 20816 | else |
| 20817 | uncasted_rhs; |
| 20818 | |
| 20806 | 20819 | const runtime_src: LazySrcLoc = src: { |
| 20807 | 20820 | if (try sema.resolveMaybeUndefVal(block, lhs_src, lhs)) |lhs_val| { |
| 20808 | 20821 | if (try sema.resolveMaybeUndefVal(block, rhs_src, rhs)) |rhs_val| { |
| ... | ... | @@ -20845,8 +20858,10 @@ fn cmpNumeric( |
| 20845 | 20858 | .Float, .ComptimeFloat => true, |
| 20846 | 20859 | else => false, |
| 20847 | 20860 | }; |
| 20861 | |
| 20848 | 20862 | if (lhs_is_float and rhs_is_float) { |
| 20849 | | // Implicit cast the smaller one to the larger one. |
| 20863 | // Smaller fixed-width floats coerce to larger fixed-width floats. |
| 20864 | // comptime_float coerces to fixed-width float. |
| 20850 | 20865 | const dest_ty = x: { |
| 20851 | 20866 | if (lhs_ty_tag == .ComptimeFloat) { |
| 20852 | 20867 | break :x rhs_ty; |