diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 40 |
1 files changed, 14 insertions, 26 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 88bce1960..1d5473d17 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -247,6 +247,19 @@ impl InferenceContext { | |||
247 | unimplemented!() | 247 | unimplemented!() |
248 | } | 248 | } |
249 | 249 | ||
250 | fn infer_path_expr(&mut self, expr: ast::PathExpr) -> Option<Ty> { | ||
251 | let p = expr.path()?; | ||
252 | if p.qualifier().is_none() { | ||
253 | let name = p.segment().and_then(|s| s.name_ref())?; | ||
254 | let scope_entry = self.scopes.resolve_local_name(name)?; | ||
255 | let ty = self.type_for.get(&scope_entry.ptr())?; | ||
256 | Some(ty.clone()) | ||
257 | } else { | ||
258 | // TODO resolve path | ||
259 | Some(Ty::Unknown) | ||
260 | } | ||
261 | } | ||
262 | |||
250 | fn infer_expr(&mut self, expr: ast::Expr) -> Ty { | 263 | fn infer_expr(&mut self, expr: ast::Expr) -> Ty { |
251 | let ty = match expr { | 264 | let ty = match expr { |
252 | ast::Expr::IfExpr(e) => { | 265 | ast::Expr::IfExpr(e) => { |
@@ -367,32 +380,7 @@ impl InferenceContext { | |||
367 | } | 380 | } |
368 | ast::Expr::TupleExpr(_e) => Ty::Unknown, | 381 | ast::Expr::TupleExpr(_e) => Ty::Unknown, |
369 | ast::Expr::ArrayExpr(_e) => Ty::Unknown, | 382 | ast::Expr::ArrayExpr(_e) => Ty::Unknown, |
370 | ast::Expr::PathExpr(e) => { | 383 | ast::Expr::PathExpr(e) => self.infer_path_expr(e).unwrap_or(Ty::Unknown), |
371 | if let Some(p) = e.path() { | ||
372 | if p.qualifier().is_none() { | ||
373 | if let Some(name) = p.segment().and_then(|s| s.name_ref()) { | ||
374 | let s = self.scopes.resolve_local_name(name); | ||
375 | if let Some(scope_entry) = s { | ||
376 | if let Some(ty) = self.type_for.get(&scope_entry.ptr()) { | ||
377 | ty.clone() | ||
378 | } else { | ||
379 | // TODO introduce type variable? | ||
380 | Ty::Unknown | ||
381 | } | ||
382 | } else { | ||
383 | Ty::Unknown | ||
384 | } | ||
385 | } else { | ||
386 | Ty::Unknown | ||
387 | } | ||
388 | } else { | ||
389 | // TODO resolve path | ||
390 | Ty::Unknown | ||
391 | } | ||
392 | } else { | ||
393 | Ty::Unknown | ||
394 | } | ||
395 | } | ||
396 | ast::Expr::ContinueExpr(_e) => Ty::Never, | 384 | ast::Expr::ContinueExpr(_e) => Ty::Never, |
397 | ast::Expr::BreakExpr(_e) => Ty::Never, | 385 | ast::Expr::BreakExpr(_e) => Ty::Never, |
398 | ast::Expr::ParenExpr(e) => { | 386 | ast::Expr::ParenExpr(e) => { |