mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
fix canonicalization
This commit is contained in:
parent
1e101599e0
commit
ed7906ccbb
2 changed files with 46 additions and 2 deletions
|
@ -158,6 +158,9 @@ pub enum Expr {
|
|||
arguments: Vec<(Variable, Located<Expr>)>,
|
||||
},
|
||||
|
||||
// Test
|
||||
Expect(Box<Located<Expr>>, Box<Located<Expr>>),
|
||||
|
||||
// Compiles, but will crash if reached
|
||||
RuntimeError(RuntimeError),
|
||||
}
|
||||
|
@ -649,9 +652,30 @@ pub fn canonicalize_expr<'a>(
|
|||
Output::default(),
|
||||
)
|
||||
}
|
||||
ast::Expr::Expect(_condition, _continuation) => todo!(),
|
||||
ast::Expr::Expect(condition, continuation) => {
|
||||
let mut output = Output::default();
|
||||
|
||||
let (loc_condition, output1) =
|
||||
canonicalize_expr(env, var_store, scope, condition.region, &condition.value);
|
||||
|
||||
let (loc_continuation, output2) = canonicalize_expr(
|
||||
env,
|
||||
var_store,
|
||||
scope,
|
||||
continuation.region,
|
||||
&continuation.value,
|
||||
);
|
||||
|
||||
output.union(output1);
|
||||
output.union(output2);
|
||||
|
||||
(
|
||||
Expect(Box::new(loc_condition), Box::new(loc_continuation)),
|
||||
output,
|
||||
)
|
||||
}
|
||||
ast::Expr::If(if_thens, final_else_branch) => {
|
||||
let mut branches = Vec::with_capacity(1);
|
||||
let mut branches = Vec::with_capacity(if_thens.len());
|
||||
let mut output = Output::default();
|
||||
|
||||
for (condition, then_branch) in if_thens.iter() {
|
||||
|
@ -1282,6 +1306,20 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) ->
|
|||
}
|
||||
}
|
||||
|
||||
Expect(loc_condition, loc_expr) => {
|
||||
let loc_condition = Located {
|
||||
region: loc_condition.region,
|
||||
value: inline_calls(var_store, scope, loc_condition.value),
|
||||
};
|
||||
|
||||
let loc_expr = Located {
|
||||
region: loc_expr.region,
|
||||
value: inline_calls(var_store, scope, loc_expr.value),
|
||||
};
|
||||
|
||||
Expect(Box::new(loc_condition), Box::new(loc_expr))
|
||||
}
|
||||
|
||||
LetRec(defs, loc_expr, var) => {
|
||||
let mut new_defs = Vec::with_capacity(defs.len());
|
||||
|
||||
|
|
|
@ -405,6 +405,12 @@ fn fix_values_captured_in_closure_expr(
|
|||
fix_values_captured_in_closure_expr(&mut loc_expr.value, no_capture_symbols);
|
||||
}
|
||||
|
||||
Expect(condition, loc_expr) => {
|
||||
// LetNonRec(Box<Def>, Box<Located<Expr>>, Variable, Aliases),
|
||||
fix_values_captured_in_closure_expr(&mut condition.value, no_capture_symbols);
|
||||
fix_values_captured_in_closure_expr(&mut loc_expr.value, no_capture_symbols);
|
||||
}
|
||||
|
||||
Closure {
|
||||
captured_symbols,
|
||||
name,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue