Type the return values of call expressions

This commit is contained in:
Florian Diebold 2018-12-23 17:16:47 +01:00
parent ef67581104
commit c85748f5fb
2 changed files with 13 additions and 5 deletions

View File

@ -211,7 +211,6 @@ impl fmt::Display for Ty {
}
pub fn type_for_fn(db: &impl HirDatabase, f: Function) -> Cancelable<Ty> {
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() {

View File

@ -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