mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 16:44:33 +00:00
commit
f45d1281f7
18 changed files with 466 additions and 138 deletions
|
@ -440,7 +440,11 @@ pub fn constrain_expr(
|
|||
constraints.exists_many(vars, cons)
|
||||
}
|
||||
|
||||
Expect(loc_cond, continuation) => {
|
||||
Expect {
|
||||
loc_condition,
|
||||
loc_continuation,
|
||||
lookups_in_cond,
|
||||
} => {
|
||||
let expect_bool = |region| {
|
||||
let bool_type = Type::Variable(Variable::BOOL);
|
||||
Expected::ForReason(Reason::ExpectCondition, bool_type, region)
|
||||
|
@ -449,20 +453,38 @@ pub fn constrain_expr(
|
|||
let cond_con = constrain_expr(
|
||||
constraints,
|
||||
env,
|
||||
loc_cond.region,
|
||||
&loc_cond.value,
|
||||
expect_bool(loc_cond.region),
|
||||
loc_condition.region,
|
||||
&loc_condition.value,
|
||||
expect_bool(loc_condition.region),
|
||||
);
|
||||
|
||||
let continuation_con = constrain_expr(
|
||||
constraints,
|
||||
env,
|
||||
continuation.region,
|
||||
&continuation.value,
|
||||
loc_continuation.region,
|
||||
&loc_continuation.value,
|
||||
expected,
|
||||
);
|
||||
|
||||
constraints.exists_many([], [cond_con, continuation_con])
|
||||
// + 2 for cond_con and continuation_con
|
||||
let mut all_constraints = Vec::with_capacity(lookups_in_cond.len() + 2);
|
||||
|
||||
all_constraints.push(cond_con);
|
||||
all_constraints.push(continuation_con);
|
||||
|
||||
let mut vars = Vec::with_capacity(lookups_in_cond.len());
|
||||
|
||||
for (symbol, var) in lookups_in_cond.iter() {
|
||||
vars.push(*var);
|
||||
|
||||
all_constraints.push(constraints.lookup(
|
||||
*symbol,
|
||||
NoExpectation(Type::Variable(*var)),
|
||||
Region::zero(),
|
||||
));
|
||||
}
|
||||
|
||||
constraints.exists_many(vars, all_constraints)
|
||||
}
|
||||
|
||||
If {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue