mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
Allow pure statements that contain early returns
This commit is contained in:
parent
6a3db1e59a
commit
d449d83a84
3 changed files with 283 additions and 9 deletions
|
@ -3394,12 +3394,18 @@ fn constrain_let_def(
|
|||
)
|
||||
});
|
||||
|
||||
// Ignored def must be effectful, otherwise it's dead code
|
||||
let effectful_constraint = Constraint::ExpectEffectful(
|
||||
fx_var,
|
||||
ExpectEffectfulReason::Ignored,
|
||||
def.loc_pattern.region,
|
||||
);
|
||||
let effectful_constraint = if def.loc_expr.value.contains_any_early_returns() {
|
||||
// If the statement has early returns, it doesn't need to be effectful to
|
||||
// potentially affect the output of the containing function
|
||||
Constraint::True
|
||||
} else {
|
||||
// If there are no early returns, it must be effectful or else it's dead code
|
||||
Constraint::ExpectEffectful(
|
||||
fx_var,
|
||||
ExpectEffectfulReason::Ignored,
|
||||
def.loc_pattern.region,
|
||||
)
|
||||
};
|
||||
|
||||
let enclosing_fx_constraint = constraints.fx_call(
|
||||
fx_var,
|
||||
|
@ -3486,9 +3492,14 @@ fn constrain_stmt_def(
|
|||
generalizable,
|
||||
);
|
||||
|
||||
// Stmt expr must be effectful, otherwise it's dead code
|
||||
let effectful_constraint =
|
||||
Constraint::ExpectEffectful(fx_var, ExpectEffectfulReason::Stmt, region);
|
||||
let effectful_constraint = if def.loc_expr.value.contains_any_early_returns() {
|
||||
// If the statement has early returns, it doesn't need to be effectful to
|
||||
// potentially affect the output of the containing function
|
||||
Constraint::True
|
||||
} else {
|
||||
// If there are no early returns, it must be effectful or else it's dead code
|
||||
Constraint::ExpectEffectful(fx_var, ExpectEffectfulReason::Stmt, region)
|
||||
};
|
||||
|
||||
let fx_call_kind = match fn_name {
|
||||
None => FxCallKind::Stmt,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue