|
1 | | -//! FIXME: write short doc here |
2 | | -use hir_def::expr::{BinaryOp, CmpOp}; |
| 1 | +//! Helper functions for binary operator type inference. |
| 2 | +use hir_def::expr::{ArithOp, BinaryOp, CmpOp}; |
3 | 3 |
|
4 | 4 | use super::{InferTy, Ty, TypeCtor}; |
5 | 5 | use crate::ApplicationTy; |
6 | 6 |
|
7 | | -pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty { |
| 7 | +pub(super) fn binary_op_return_ty(op: BinaryOp, lhs_ty: Ty, rhs_ty: Ty) -> Ty { |
8 | 8 | match op { |
9 | 9 | BinaryOp::LogicOp(_) | BinaryOp::CmpOp(_) => Ty::simple(TypeCtor::Bool), |
10 | 10 | BinaryOp::Assignment { .. } => Ty::unit(), |
| 11 | + BinaryOp::ArithOp(ArithOp::Shl) | BinaryOp::ArithOp(ArithOp::Shr) => match lhs_ty { |
| 12 | + Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { |
| 13 | + TypeCtor::Int(..) | TypeCtor::Float(..) => lhs_ty, |
| 14 | + _ => Ty::Unknown, |
| 15 | + }, |
| 16 | + Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty, |
| 17 | + _ => Ty::Unknown, |
| 18 | + }, |
11 | 19 | BinaryOp::ArithOp(_) => match rhs_ty { |
12 | 20 | Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { |
13 | 21 | TypeCtor::Int(..) | TypeCtor::Float(..) => rhs_ty, |
@@ -36,6 +44,7 @@ pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty { |
36 | 44 | _ => Ty::Unknown, |
37 | 45 | } |
38 | 46 | } |
| 47 | + BinaryOp::ArithOp(ArithOp::Shl) | BinaryOp::ArithOp(ArithOp::Shr) => Ty::Unknown, |
39 | 48 | BinaryOp::CmpOp(CmpOp::Ord { .. }) |
40 | 49 | | BinaryOp::Assignment { op: Some(_) } |
41 | 50 | | BinaryOp::ArithOp(_) => match lhs_ty { |
|
0 commit comments