aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/op.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty/op.rs')
-rw-r--r--crates/ra_hir/src/ty/op.rs33
1 files changed, 23 insertions, 10 deletions
diff --git a/crates/ra_hir/src/ty/op.rs b/crates/ra_hir/src/ty/op.rs
index 8703cf236..f581004d2 100644
--- a/crates/ra_hir/src/ty/op.rs
+++ b/crates/ra_hir/src/ty/op.rs
@@ -1,5 +1,5 @@
1use crate::expr::BinaryOp; 1use crate::{ ty::ApplicationTy, expr::BinaryOp};
2use super::{Ty, InferTy}; 2use super::{Ty, TypeName, InferTy};
3 3
4pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty { 4pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty {
5 match op { 5 match op {
@@ -10,7 +10,7 @@ pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty {
10 | BinaryOp::LesserEqualTest 10 | BinaryOp::LesserEqualTest
11 | BinaryOp::GreaterEqualTest 11 | BinaryOp::GreaterEqualTest
12 | BinaryOp::LesserTest 12 | BinaryOp::LesserTest
13 | BinaryOp::GreaterTest => Ty::Bool, 13 | BinaryOp::GreaterTest => Ty::simple(TypeName::Bool),
14 BinaryOp::Assignment 14 BinaryOp::Assignment
15 | BinaryOp::AddAssign 15 | BinaryOp::AddAssign
16 | BinaryOp::SubAssign 16 | BinaryOp::SubAssign
@@ -32,10 +32,11 @@ pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty {
32 | BinaryOp::BitwiseAnd 32 | BinaryOp::BitwiseAnd
33 | BinaryOp::BitwiseOr 33 | BinaryOp::BitwiseOr
34 | BinaryOp::BitwiseXor => match rhs_ty { 34 | BinaryOp::BitwiseXor => match rhs_ty {
35 Ty::Int(..) 35 Ty::Apply(ApplicationTy { name, .. }) => match name {
36 | Ty::Float(..) 36 TypeName::Int(..) | TypeName::Float(..) => rhs_ty,
37 | Ty::Infer(InferTy::IntVar(..)) 37 _ => Ty::Unknown,
38 | Ty::Infer(InferTy::FloatVar(..)) => rhs_ty, 38 },
39 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => rhs_ty,
39 _ => Ty::Unknown, 40 _ => Ty::Unknown,
40 }, 41 },
41 BinaryOp::RangeRightOpen | BinaryOp::RangeRightClosed => Ty::Unknown, 42 BinaryOp::RangeRightOpen | BinaryOp::RangeRightClosed => Ty::Unknown,
@@ -44,9 +45,17 @@ pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty {
44 45
45pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty { 46pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty {
46 match op { 47 match op {
47 BinaryOp::BooleanAnd | BinaryOp::BooleanOr => Ty::Bool, 48 BinaryOp::BooleanAnd | BinaryOp::BooleanOr => Ty::simple(TypeName::Bool),
48 BinaryOp::Assignment | BinaryOp::EqualityTest => match lhs_ty { 49 BinaryOp::Assignment | BinaryOp::EqualityTest => match lhs_ty {
49 Ty::Int(..) | Ty::Float(..) | Ty::Str | Ty::Char | Ty::Bool => lhs_ty, 50 Ty::Apply(ApplicationTy { name, .. }) => match name {
51 TypeName::Int(..)
52 | TypeName::Float(..)
53 | TypeName::Str
54 | TypeName::Char
55 | TypeName::Bool => lhs_ty,
56 _ => Ty::Unknown,
57 },
58 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty,
50 _ => Ty::Unknown, 59 _ => Ty::Unknown,
51 }, 60 },
52 BinaryOp::LesserEqualTest 61 BinaryOp::LesserEqualTest
@@ -73,7 +82,11 @@ pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty {
73 | BinaryOp::BitwiseAnd 82 | BinaryOp::BitwiseAnd
74 | BinaryOp::BitwiseOr 83 | BinaryOp::BitwiseOr
75 | BinaryOp::BitwiseXor => match lhs_ty { 84 | BinaryOp::BitwiseXor => match lhs_ty {
76 Ty::Int(..) | Ty::Float(..) => lhs_ty, 85 Ty::Apply(ApplicationTy { name, .. }) => match name {
86 TypeName::Int(..) | TypeName::Float(..) => lhs_ty,
87 _ => Ty::Unknown,
88 },
89 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty,
77 _ => Ty::Unknown, 90 _ => Ty::Unknown,
78 }, 91 },
79 _ => Ty::Unknown, 92 _ => Ty::Unknown,