diff options
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 66940ec30..74996dda5 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -36,7 +36,7 @@ use crate::{ | |||
36 | db::HirDatabase, | 36 | db::HirDatabase, |
37 | type_ref::{TypeRef, Mutability}, | 37 | type_ref::{TypeRef, Mutability}, |
38 | name::KnownName, | 38 | name::KnownName, |
39 | expr::{Body, Expr, Literal, ExprId, Pat, PatId, UnaryOp, BinaryOp, Statement, FieldPat}, | 39 | expr::{Body, Expr, MatchArm, Literal, ExprId, Pat, PatId, UnaryOp, BinaryOp, Statement, FieldPat}, |
40 | }; | 40 | }; |
41 | 41 | ||
42 | /// The ID of a type variable. | 42 | /// The ID of a type variable. |
@@ -1097,14 +1097,24 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1097 | ret_ty | 1097 | ret_ty |
1098 | } | 1098 | } |
1099 | Expr::Match { expr, arms } => { | 1099 | Expr::Match { expr, arms } => { |
1100 | let _ty = self.infer_expr(*expr, &Expectation::none()); | 1100 | let mut expected = Expectation::none(); |
1101 | for arm in arms { | 1101 | let input_ty = self.infer_expr(*expr, &Expectation::none()); |
1102 | // TODO type the bindings in pats | 1102 | let pat_expectation = Expectation::has_type(input_ty); |
1103 | |||
1104 | for MatchArm { | ||
1105 | pats, | ||
1106 | expr: arm_expr, | ||
1107 | } in arms | ||
1108 | { | ||
1109 | for &pat in pats { | ||
1110 | let _pat_ty = self.infer_pat(pat, &pat_expectation); | ||
1111 | } | ||
1103 | // TODO type the guard | 1112 | // TODO type the guard |
1104 | let _ty = self.infer_expr(arm.expr, &Expectation::none()); | 1113 | let ty = self.infer_expr(*arm_expr, &expected); |
1114 | expected = Expectation::has_type(ty); | ||
1105 | } | 1115 | } |
1106 | // TODO unify all the match arm types | 1116 | |
1107 | Ty::Unknown | 1117 | expected.ty |
1108 | } | 1118 | } |
1109 | Expr::Path(p) => self.infer_path_expr(expr, p).unwrap_or(Ty::Unknown), | 1119 | Expr::Path(p) => self.infer_path_expr(expr, p).unwrap_or(Ty::Unknown), |
1110 | Expr::Continue => Ty::Never, | 1120 | Expr::Continue => Ty::Never, |