diff options
author | Florian Diebold <[email protected]> | 2021-06-03 22:12:35 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2021-06-12 22:04:43 +0100 |
commit | 20487a1b4a7c2fdffdb1de61c7837ee6f673f21a (patch) | |
tree | da558f908e41a890ed99f0166d23d1c2078e0053 /crates/hir_ty/src/infer | |
parent | 124123a53bfbd32be5d63315885d2d5c9e3a1ee6 (diff) |
Fix coercion in match with expected type
Plus add infrastructure to test type mismatches without expect.
Diffstat (limited to 'crates/hir_ty/src/infer')
-rw-r--r-- | crates/hir_ty/src/infer/expr.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index f73bf43b2..e34f194ff 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs | |||
@@ -337,10 +337,15 @@ impl<'a> InferenceContext<'a> { | |||
337 | Expr::Match { expr, arms } => { | 337 | Expr::Match { expr, arms } => { |
338 | let input_ty = self.infer_expr(*expr, &Expectation::none()); | 338 | let input_ty = self.infer_expr(*expr, &Expectation::none()); |
339 | 339 | ||
340 | let expected = expected.adjust_for_branches(&mut self.table); | ||
341 | |||
340 | let mut result_ty = if arms.is_empty() { | 342 | let mut result_ty = if arms.is_empty() { |
341 | TyKind::Never.intern(&Interner) | 343 | TyKind::Never.intern(&Interner) |
342 | } else { | 344 | } else { |
343 | self.table.new_type_var() | 345 | match &expected { |
346 | Expectation::HasType(ty) => ty.clone(), | ||
347 | _ => self.table.new_type_var(), | ||
348 | } | ||
344 | }; | 349 | }; |
345 | 350 | ||
346 | let matchee_diverges = self.diverges; | 351 | let matchee_diverges = self.diverges; |