aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-01-25 20:32:49 +0000
committerFlorian Diebold <[email protected]>2019-01-25 20:32:49 +0000
commit5a1385007cb7509d50a77afa5a47ed0685f7f2f9 (patch)
treec996152aa889c1ef7c6af18ae88f328a2ba2c5fb
parent03fc615ead78ecf126632220104fa4de3414eb7f (diff)
Fix type inference of binops on int/float variables
Fixes #651.
-rw-r--r--crates/ra_hir/src/ty.rs5
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__bug_651.snap13
-rw-r--r--crates/ra_hir/src/ty/tests.rs13
3 files changed, 30 insertions, 1 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 714eaaae5..179ebddee 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -790,7 +790,10 @@ fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty {
790 | BinaryOp::BitwiseAnd 790 | BinaryOp::BitwiseAnd
791 | BinaryOp::BitwiseOr 791 | BinaryOp::BitwiseOr
792 | BinaryOp::BitwiseXor => match rhs_ty { 792 | BinaryOp::BitwiseXor => match rhs_ty {
793 Ty::Int(..) | Ty::Float(..) => rhs_ty, 793 Ty::Int(..)
794 | Ty::Float(..)
795 | Ty::Infer(InferTy::IntVar(..))
796 | Ty::Infer(InferTy::FloatVar(..)) => rhs_ty,
794 _ => Ty::Unknown, 797 _ => Ty::Unknown,
795 }, 798 },
796 BinaryOp::RangeRightOpen | BinaryOp::RangeRightClosed => Ty::Unknown, 799 BinaryOp::RangeRightOpen | BinaryOp::RangeRightClosed => Ty::Unknown,
diff --git a/crates/ra_hir/src/ty/snapshots/tests__bug_651.snap b/crates/ra_hir/src/ty/snapshots/tests__bug_651.snap
new file mode 100644
index 000000000..d23d3f139
--- /dev/null
+++ b/crates/ra_hir/src/ty/snapshots/tests__bug_651.snap
@@ -0,0 +1,13 @@
1---
2created: "2019-01-25T20:31:47.275112244+00:00"
3creator: [email protected]
4expression: "&result"
5source: crates/ra_hir/src/ty/tests.rs
6---
7[11; 41) '{ ...+ y; }': ()
8[21; 22) 'y': i32
9[25; 27) '92': i32
10[33; 34) '1': i32
11[33; 38) '1 + y': i32
12[37; 38) 'y': i32
13
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index 92c74cf00..389bdaf23 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -532,6 +532,19 @@ fn test() {
532 ); 532 );
533} 533}
534 534
535#[test]
536fn bug_651() {
537 check_inference(
538 "bug_651",
539 r#"
540fn quux() {
541 let y = 92;
542 1 + y;
543}
544"#,
545 );
546}
547
535fn infer(content: &str) -> String { 548fn infer(content: &str) -> String {
536 let (db, _, file_id) = MockDatabase::with_single_file(content); 549 let (db, _, file_id) = MockDatabase::with_single_file(content);
537 let source_file = db.source_file(file_id); 550 let source_file = db.source_file(file_id);