1834bae5b8
This wasn't a right decision in the first place, the feature flag was broken in the last rustfmt release, and syntax highlighting of imports is more important anyway
95 lines
3.2 KiB
Rust
95 lines
3.2 KiB
Rust
use super::{InferTy, Ty, TypeCtor};
|
|
use crate::{expr::BinaryOp, ty::ApplicationTy};
|
|
|
|
pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty {
|
|
match op {
|
|
BinaryOp::BooleanOr
|
|
| BinaryOp::BooleanAnd
|
|
| BinaryOp::EqualityTest
|
|
| BinaryOp::NegatedEqualityTest
|
|
| BinaryOp::LesserEqualTest
|
|
| BinaryOp::GreaterEqualTest
|
|
| BinaryOp::LesserTest
|
|
| BinaryOp::GreaterTest => Ty::simple(TypeCtor::Bool),
|
|
BinaryOp::Assignment
|
|
| BinaryOp::AddAssign
|
|
| BinaryOp::SubAssign
|
|
| BinaryOp::DivAssign
|
|
| BinaryOp::MulAssign
|
|
| BinaryOp::RemAssign
|
|
| BinaryOp::ShrAssign
|
|
| BinaryOp::ShlAssign
|
|
| BinaryOp::BitAndAssign
|
|
| BinaryOp::BitOrAssign
|
|
| BinaryOp::BitXorAssign => Ty::unit(),
|
|
BinaryOp::Addition
|
|
| BinaryOp::Subtraction
|
|
| BinaryOp::Multiplication
|
|
| BinaryOp::Division
|
|
| BinaryOp::Remainder
|
|
| BinaryOp::LeftShift
|
|
| BinaryOp::RightShift
|
|
| BinaryOp::BitwiseAnd
|
|
| BinaryOp::BitwiseOr
|
|
| BinaryOp::BitwiseXor => match rhs_ty {
|
|
Ty::Apply(ApplicationTy { ctor, .. }) => match ctor {
|
|
TypeCtor::Int(..) | TypeCtor::Float(..) => rhs_ty,
|
|
_ => Ty::Unknown,
|
|
},
|
|
Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => rhs_ty,
|
|
_ => Ty::Unknown,
|
|
},
|
|
BinaryOp::RangeRightOpen | BinaryOp::RangeRightClosed => Ty::Unknown,
|
|
}
|
|
}
|
|
|
|
pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty {
|
|
match op {
|
|
BinaryOp::BooleanAnd | BinaryOp::BooleanOr => Ty::simple(TypeCtor::Bool),
|
|
BinaryOp::Assignment | BinaryOp::EqualityTest => match lhs_ty {
|
|
Ty::Apply(ApplicationTy { ctor, .. }) => match ctor {
|
|
TypeCtor::Int(..)
|
|
| TypeCtor::Float(..)
|
|
| TypeCtor::Str
|
|
| TypeCtor::Char
|
|
| TypeCtor::Bool => lhs_ty,
|
|
_ => Ty::Unknown,
|
|
},
|
|
Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty,
|
|
_ => Ty::Unknown,
|
|
},
|
|
BinaryOp::LesserEqualTest
|
|
| BinaryOp::GreaterEqualTest
|
|
| BinaryOp::LesserTest
|
|
| BinaryOp::GreaterTest
|
|
| BinaryOp::AddAssign
|
|
| BinaryOp::SubAssign
|
|
| BinaryOp::DivAssign
|
|
| BinaryOp::MulAssign
|
|
| BinaryOp::RemAssign
|
|
| BinaryOp::ShrAssign
|
|
| BinaryOp::ShlAssign
|
|
| BinaryOp::BitAndAssign
|
|
| BinaryOp::BitOrAssign
|
|
| BinaryOp::BitXorAssign
|
|
| BinaryOp::Addition
|
|
| BinaryOp::Subtraction
|
|
| BinaryOp::Multiplication
|
|
| BinaryOp::Division
|
|
| BinaryOp::Remainder
|
|
| BinaryOp::LeftShift
|
|
| BinaryOp::RightShift
|
|
| BinaryOp::BitwiseAnd
|
|
| BinaryOp::BitwiseOr
|
|
| BinaryOp::BitwiseXor => match lhs_ty {
|
|
Ty::Apply(ApplicationTy { ctor, .. }) => match ctor {
|
|
TypeCtor::Int(..) | TypeCtor::Float(..) => lhs_ty,
|
|
_ => Ty::Unknown,
|
|
},
|
|
Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty,
|
|
_ => Ty::Unknown,
|
|
},
|
|
_ => Ty::Unknown,
|
|
}
|
|
}
|