mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
Constrain early returns in functions in addition to closures
This commit is contained in:
parent
dfb2966281
commit
9a2b99c148
2 changed files with 58 additions and 0 deletions
|
@ -2114,6 +2114,21 @@ fn constrain_function_def(
|
|||
ret_type_index,
|
||||
));
|
||||
|
||||
let mut early_return_constraints = Vec::with_capacity(function_def.early_returns.len());
|
||||
for (early_return_variable, early_return_region) in &function_def.early_returns {
|
||||
let early_return_var = constraints.push_variable(*early_return_variable);
|
||||
let early_return_con = constraints.equal_types(
|
||||
early_return_var,
|
||||
return_type_annotation_expected,
|
||||
Category::Return,
|
||||
*early_return_region,
|
||||
);
|
||||
|
||||
early_return_constraints.push(early_return_con);
|
||||
}
|
||||
|
||||
let early_returns_constraint = constraints.and_constraint(early_return_constraints);
|
||||
|
||||
let solved_fn_type = {
|
||||
// TODO(types-soa) optimize for Variable
|
||||
let pattern_types = types.from_old_type_slice(
|
||||
|
@ -2151,6 +2166,7 @@ fn constrain_function_def(
|
|||
std::file!(),
|
||||
std::line!(),
|
||||
),
|
||||
early_returns_constraint,
|
||||
constraints.let_constraint(
|
||||
[],
|
||||
argument_pattern_state.vars,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue