aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2021-05-15 18:35:12 +0100
committerFlorian Diebold <[email protected]>2021-05-21 16:48:34 +0100
commitb939a6dcacc0460f49781e922c979d235a52eeca (patch)
tree0d05471a221455d53c1caffbcd0d705ddb5a5241 /crates
parent212f0477f29ec27a3981a916de432fc9ef872ff3 (diff)
Fix if/else coercion
Diffstat (limited to 'crates')
-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(