aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/hir_ty/src/infer/expr.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index aab4d3153..f439169ea 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -131,17 +131,20 @@ impl<'a> InferenceContext<'a> {
131 let condition_diverges = mem::replace(&mut self.diverges, Diverges::Maybe); 131 let condition_diverges = mem::replace(&mut self.diverges, Diverges::Maybe);
132 let mut both_arms_diverge = Diverges::Always; 132 let mut both_arms_diverge = Diverges::Always;
133 133
134 let mut result_ty = self.table.new_type_var();
134 let then_ty = self.infer_expr_inner(*then_branch, &expected); 135 let then_ty = self.infer_expr_inner(*then_branch, &expected);
135 both_arms_diverge &= mem::replace(&mut self.diverges, Diverges::Maybe); 136 both_arms_diverge &= mem::replace(&mut self.diverges, Diverges::Maybe);
137 result_ty = self.coerce_merge_branch(&result_ty, &then_ty);
136 let else_ty = match else_branch { 138 let else_ty = match else_branch {
137 Some(else_branch) => self.infer_expr_inner(*else_branch, &expected), 139 Some(else_branch) => self.infer_expr_inner(*else_branch, &expected),
138 None => TyBuilder::unit(), 140 None => TyBuilder::unit(),
139 }; 141 };
140 both_arms_diverge &= self.diverges; 142 both_arms_diverge &= self.diverges;
143 result_ty = self.coerce_merge_branch(&result_ty, &else_ty);
141 144
142 self.diverges = condition_diverges | both_arms_diverge; 145 self.diverges = condition_diverges | both_arms_diverge;
143 146
144 self.coerce_merge_branch(&then_ty, &else_ty) 147 result_ty
145 } 148 }
146 Expr::Block { statements, tail, label, id: _ } => { 149 Expr::Block { statements, tail, label, id: _ } => {
147 let old_resolver = mem::replace( 150 let old_resolver = mem::replace(