diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-06-12 22:05:12 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-06-12 22:05:12 +0100 |
commit | d6737e55fb49d286b5e646f57975b27b2c95ce92 (patch) | |
tree | 8d79fe8e63f8154e2e331660442aee83d99904a4 /crates/hir_ty/src/infer | |
parent | 7bbb3e34d5e2ca25b6987bf679cb9962bd0c52b6 (diff) | |
parent | 20487a1b4a7c2fdffdb1de61c7837ee6f673f21a (diff) |
Merge #9239
9239: fix: Fix coercion in match with expected type r=flodiebold a=flodiebold
Plus add infrastructure to test type mismatches without expect.
CC #8961
Co-authored-by: Florian Diebold <[email protected]>
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; |