aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/ty.rs24
-rw-r--r--crates/ra_hir/src/ty/tests/data/adt_pattern.txt9
2 files changed, 25 insertions, 8 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,
diff --git a/crates/ra_hir/src/ty/tests/data/adt_pattern.txt b/crates/ra_hir/src/ty/tests/data/adt_pattern.txt
index 41e9c9d34..3b9b9a078 100644
--- a/crates/ra_hir/src/ty/tests/data/adt_pattern.txt
+++ b/crates/ra_hir/src/ty/tests/data/adt_pattern.txt
@@ -1,4 +1,4 @@
1[68; 155) '{ ...= e; }': () 1[68; 221) '{ ... }; }': ()
2[78; 79) 'e': E 2[78; 79) 'e': E
3[82; 95) 'E::A { x: 3 }': E 3[82; 95) 'E::A { x: 3 }': E
4[92; 93) '3': usize 4[92; 93) '3': usize
@@ -9,3 +9,10 @@
9[129; 148) 'E::A {..._var }': E 9[129; 148) 'E::A {..._var }': E
10[139; 146) 'new_var': usize 10[139; 146) 'new_var': usize
11[151; 152) 'e': E 11[151; 152) 'e': E
12[159; 218) 'match ... }': usize
13[165; 166) 'e': E
14[177; 187) 'E::A { x }': E
15[184; 185) 'x': usize
16[191; 192) 'x': usize
17[202; 206) 'E::B': E
18[210; 211) '1': usize