diff options
author | Kirill Bulatov <[email protected]> | 2019-08-14 20:20:18 +0100 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2019-08-26 20:44:50 +0100 |
commit | 44cf7b34fe1a486168590f7fead442f12602c419 (patch) | |
tree | cc57761879baba138231882b4147bade8bc4bfbd /crates/ra_hir/src/ty/infer.rs | |
parent | c1f47c37886b5cba116ba99fa37977d51871eba4 (diff) |
Fix never in if expressions
Diffstat (limited to 'crates/ra_hir/src/ty/infer.rs')
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index b310bf6bd..d01063766 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs | |||
@@ -987,14 +987,21 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
987 | let then_ty = self.infer_expr(*then_branch, expected); | 987 | let then_ty = self.infer_expr(*then_branch, expected); |
988 | match else_branch { | 988 | match else_branch { |
989 | Some(else_branch) => { | 989 | Some(else_branch) => { |
990 | self.infer_expr(*else_branch, expected); | 990 | let else_ty = self.infer_expr(*else_branch, expected); |
991 | if Self::is_never(&then_ty) { | ||
992 | tested_by!(if_never); | ||
993 | else_ty | ||
994 | } else { | ||
995 | tested_by!(if_else_never); | ||
996 | then_ty | ||
997 | } | ||
991 | } | 998 | } |
992 | None => { | 999 | None => { |
993 | // no else branch -> unit | 1000 | // no else branch -> unit |
994 | self.unify(&then_ty, &Ty::unit()); // actually coerce | 1001 | self.unify(&then_ty, &Ty::unit()); // actually coerce |
1002 | then_ty | ||
995 | } | 1003 | } |
996 | }; | 1004 | } |
997 | then_ty | ||
998 | } | 1005 | } |
999 | Expr::Block { statements, tail } => self.infer_block(statements, *tail, expected), | 1006 | Expr::Block { statements, tail } => self.infer_block(statements, *tail, expected), |
1000 | Expr::TryBlock { body } => { | 1007 | Expr::TryBlock { body } => { |