From c85748f5fbe308610261da91aeb978eca751a0ff Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 23 Dec 2018 17:16:47 +0100 Subject: Type the return values of call expressions --- crates/ra_hir/src/ty.rs | 14 +++++++++++--- crates/ra_hir/src/ty/tests/data/0003_paths.txt | 4 ++-- 2 files changed, 13 insertions(+), 5 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 13ee6cb27..92de9842c 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -211,7 +211,6 @@ impl fmt::Display for Ty { } pub fn type_for_fn(db: &impl HirDatabase, f: Function) -> Cancelable { - eprintln!("type_for_fn {:?}", f.fn_id); let syntax = f.syntax(db); let node = syntax.borrowed(); // TODO we ignore type parameters for now @@ -397,7 +396,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { Ty::Unknown } ast::Expr::CallExpr(e) => { - let _callee_ty = if let Some(e) = e.expr() { + let callee_ty = if let Some(e) = e.expr() { self.infer_expr(e)? } else { Ty::Unknown @@ -408,7 +407,16 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { self.infer_expr(arg)?; } } - Ty::Unknown + match callee_ty { + Ty::FnPtr(sig) => { + sig.output.clone() + } + _ => { + // not callable + // TODO report an error? + Ty::Unknown + } + } } ast::Expr::MethodCallExpr(e) => { let _receiver_ty = if let Some(e) = e.expr() { diff --git a/crates/ra_hir/src/ty/tests/data/0003_paths.txt b/crates/ra_hir/src/ty/tests/data/0003_paths.txt index 3a53370a2..acde9b7ad 100644 --- a/crates/ra_hir/src/ty/tests/data/0003_paths.txt +++ b/crates/ra_hir/src/ty/tests/data/0003_paths.txt @@ -2,8 +2,8 @@ [14; 19) '{ 1 }': [unknown] [47; 52) '{ 1 }': [unknown] [49; 50) '1': [unknown] -[81; 87) 'b::c()': [unknown] +[81; 87) 'b::c()': u32 [66; 90) '{ ...c(); }': () [72; 73) 'a': fn() -> u32 -[72; 75) 'a()': [unknown] +[72; 75) 'a()': u32 [81; 85) 'b::c': fn() -> u32 -- cgit v1.2.3