Merge #655
655: Fix type inference of binops on int/float variables r=matklad a=flodiebold Fixes #651. Co-authored-by: Florian Diebold <flodiebold@gmail.com>
This commit is contained in:
commit
d0ddc5a7c1
3 changed files with 30 additions and 1 deletions
|
@ -790,7 +790,10 @@ fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty {
|
|||
| BinaryOp::BitwiseAnd
|
||||
| BinaryOp::BitwiseOr
|
||||
| BinaryOp::BitwiseXor => match rhs_ty {
|
||||
Ty::Int(..) | Ty::Float(..) => rhs_ty,
|
||||
Ty::Int(..)
|
||||
| Ty::Float(..)
|
||||
| Ty::Infer(InferTy::IntVar(..))
|
||||
| Ty::Infer(InferTy::FloatVar(..)) => rhs_ty,
|
||||
_ => Ty::Unknown,
|
||||
},
|
||||
BinaryOp::RangeRightOpen | BinaryOp::RangeRightClosed => Ty::Unknown,
|
||||
|
|
13
crates/ra_hir/src/ty/snapshots/tests__bug_651.snap
Normal file
13
crates/ra_hir/src/ty/snapshots/tests__bug_651.snap
Normal file
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
created: "2019-01-25T20:31:47.275112244+00:00"
|
||||
creator: insta@0.5.2
|
||||
expression: "&result"
|
||||
source: crates/ra_hir/src/ty/tests.rs
|
||||
---
|
||||
[11; 41) '{ ...+ y; }': ()
|
||||
[21; 22) 'y': i32
|
||||
[25; 27) '92': i32
|
||||
[33; 34) '1': i32
|
||||
[33; 38) '1 + y': i32
|
||||
[37; 38) 'y': i32
|
||||
|
|
@ -532,6 +532,19 @@ fn test() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bug_651() {
|
||||
check_inference(
|
||||
"bug_651",
|
||||
r#"
|
||||
fn quux() {
|
||||
let y = 92;
|
||||
1 + y;
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
fn infer(content: &str) -> String {
|
||||
let (db, _, file_id) = MockDatabase::with_single_file(content);
|
||||
let source_file = db.source_file(file_id);
|
||||
|
|
Loading…
Add table
Reference in a new issue