if a function returns a record/tag, do the perceus thing

This commit is contained in:
Folkert 2021-05-23 16:13:46 +02:00
parent bbca98a4db
commit c3af4522bf

View file

@ -421,7 +421,10 @@ fn expand_and_cancel<'a>(env: &mut Env<'a, '_>, stmt: &'a Stmt<'a>) -> &'a Stmt<
// prevent long chains of `Let`s from blowing the stack // prevent long chains of `Let`s from blowing the stack
let mut literal_stack = Vec::new_in(env.arena); let mut literal_stack = Vec::new_in(env.arena);
while !matches!(&expr, Expr::AccessAtIndex { .. } | Expr::Struct(_)) { while !matches!(
&expr,
Expr::AccessAtIndex { .. } | Expr::Struct(_) | Expr::Call(_)
) {
if let Stmt::Let(symbol1, expr1, layout1, cont1) = cont { if let Stmt::Let(symbol1, expr1, layout1, cont1) = cont {
literal_stack.push((symbol, expr.clone(), *layout)); literal_stack.push((symbol, expr.clone(), *layout));
@ -483,6 +486,17 @@ fn expand_and_cancel<'a>(env: &mut Env<'a, '_>, stmt: &'a Stmt<'a>) -> &'a Stmt<
new_cont = expand_and_cancel(env, cont); new_cont = expand_and_cancel(env, cont);
} }
} }
Expr::Call(_) => {
if let Layout::Struct(fields) = layout {
env.insert_struct_info(symbol, fields);
new_cont = expand_and_cancel(env, cont);
env.remove_struct_info(symbol);
} else {
new_cont = expand_and_cancel(env, cont);
}
}
_ => { _ => {
new_cont = expand_and_cancel(env, cont); new_cont = expand_and_cancel(env, cont);
} }