mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
fix bug in constraint gen for If
the condition expression wasn't actually constrained
This commit is contained in:
parent
7f358cd14c
commit
aeeaf99c17
1 changed files with 20 additions and 7 deletions
|
@ -328,16 +328,27 @@ pub fn constrain_expr(
|
|||
} => {
|
||||
let bool_type = Type::Variable(Variable::BOOL);
|
||||
let expect_bool = Expected::ForReason(Reason::IfCondition, bool_type, region);
|
||||
let mut branch_cons = Vec::with_capacity(2 * branches.len() + 2);
|
||||
let mut branch_cons = Vec::with_capacity(2 * branches.len() + 3);
|
||||
|
||||
// TODO why does this cond var exist? is it for error messages?
|
||||
let cond_var_is_bool_con = Eq(
|
||||
Type::Variable(*cond_var),
|
||||
expect_bool.clone(),
|
||||
Region::zero(),
|
||||
);
|
||||
|
||||
branch_cons.push(cond_var_is_bool_con);
|
||||
|
||||
match expected {
|
||||
FromAnnotation(name, arity, _, tipe) => {
|
||||
for (index, (loc_cond, loc_body)) in branches.iter().enumerate() {
|
||||
let cond_con = Eq(
|
||||
Type::Variable(*cond_var),
|
||||
expect_bool.clone(),
|
||||
let cond_con = constrain_expr(
|
||||
env,
|
||||
loc_cond.region,
|
||||
&loc_cond.value,
|
||||
expect_bool.clone(),
|
||||
);
|
||||
|
||||
let then_con = constrain_expr(
|
||||
env,
|
||||
loc_body.region,
|
||||
|
@ -374,11 +385,13 @@ pub fn constrain_expr(
|
|||
}
|
||||
_ => {
|
||||
for (index, (loc_cond, loc_body)) in branches.iter().enumerate() {
|
||||
let cond_con = Eq(
|
||||
Type::Variable(*cond_var),
|
||||
expect_bool.clone(),
|
||||
let cond_con = constrain_expr(
|
||||
env,
|
||||
loc_cond.region,
|
||||
&loc_cond.value,
|
||||
expect_bool.clone(),
|
||||
);
|
||||
|
||||
let then_con = constrain_expr(
|
||||
env,
|
||||
loc_body.region,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue