From 44cf7b34fe1a486168590f7fead442f12602c419 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 14 Aug 2019 22:20:18 +0300 Subject: Fix never in if expressions --- crates/ra_hir/src/ty/infer.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir/src/ty/infer.rs') 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> { let then_ty = self.infer_expr(*then_branch, expected); match else_branch { Some(else_branch) => { - self.infer_expr(*else_branch, expected); + let else_ty = self.infer_expr(*else_branch, expected); + if Self::is_never(&then_ty) { + tested_by!(if_never); + else_ty + } else { + tested_by!(if_else_never); + then_ty + } } None => { // no else branch -> unit self.unify(&then_ty, &Ty::unit()); // actually coerce + then_ty } - }; - then_ty + } } Expr::Block { statements, tail } => self.infer_block(statements, *tail, expected), Expr::TryBlock { body } => { -- cgit v1.2.3