diff options
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index f32c77faf..562ad1f49 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -1381,12 +1381,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1381 | Expr::MethodCall { receiver, args, method_name, generic_args } => { | 1381 | Expr::MethodCall { receiver, args, method_name, generic_args } => { |
1382 | let receiver_ty = self.infer_expr(*receiver, &Expectation::none()); | 1382 | let receiver_ty = self.infer_expr(*receiver, &Expectation::none()); |
1383 | let resolved = receiver_ty.clone().lookup_method(self.db, method_name); | 1383 | let resolved = receiver_ty.clone().lookup_method(self.db, method_name); |
1384 | let (method_ty, def_generics) = match resolved { | 1384 | let (derefed_receiver_ty, method_ty, def_generics) = match resolved { |
1385 | Some(func) => { | 1385 | Some((ty, func)) => { |
1386 | self.write_method_resolution(tgt_expr, func); | 1386 | self.write_method_resolution(tgt_expr, func); |
1387 | (self.db.type_for_def(func.into()), Some(func.generic_params(self.db))) | 1387 | (ty, self.db.type_for_def(func.into()), Some(func.generic_params(self.db))) |
1388 | } | 1388 | } |
1389 | None => (Ty::Unknown, None), | 1389 | None => (Ty::Unknown, receiver_ty, None), |
1390 | }; | 1390 | }; |
1391 | // handle provided type arguments | 1391 | // handle provided type arguments |
1392 | let method_ty = if let Some(generic_args) = generic_args { | 1392 | let method_ty = if let Some(generic_args) = generic_args { |
@@ -1429,9 +1429,13 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1429 | } | 1429 | } |
1430 | _ => (Ty::Unknown, Vec::new(), Ty::Unknown), | 1430 | _ => (Ty::Unknown, Vec::new(), Ty::Unknown), |
1431 | }; | 1431 | }; |
1432 | // TODO we would have to apply the autoderef/autoref steps here | 1432 | // Apply autoref so the below unification works correctly |
1433 | // to get the correct receiver type to unify... | 1433 | let actual_receiver_ty = match expected_receiver_ty { |
1434 | self.unify(&expected_receiver_ty, &receiver_ty); | 1434 | Ty::Ref(_, mutability) => Ty::Ref(Arc::new(derefed_receiver_ty), mutability), |
1435 | _ => derefed_receiver_ty, | ||
1436 | }; | ||
1437 | self.unify(&expected_receiver_ty, &actual_receiver_ty); | ||
1438 | |||
1435 | let param_iter = param_tys.into_iter().chain(repeat(Ty::Unknown)); | 1439 | let param_iter = param_tys.into_iter().chain(repeat(Ty::Unknown)); |
1436 | for (arg, param) in args.iter().zip(param_iter) { | 1440 | for (arg, param) in args.iter().zip(param_iter) { |
1437 | self.infer_expr(*arg, &Expectation::has_type(param)); | 1441 | self.infer_expr(*arg, &Expectation::has_type(param)); |