feat(mono): return Stmt::RuntimeError on bad layouts for If

This commit is contained in:
rvcas 2021-07-03 13:05:30 -04:00
parent 16542f0e1e
commit 39d39c218f

View file

@ -3150,13 +3150,11 @@ pub fn with_hole<'a>(
branches, branches,
final_else, final_else,
} => { } => {
let ret_layout = layout_cache match (
.from_var(env.arena, branch_var, env.subs) layout_cache.from_var(env.arena, branch_var, env.subs),
.expect("invalid ret_layout"); layout_cache.from_var(env.arena, cond_var, env.subs),
let cond_layout = layout_cache ) {
.from_var(env.arena, cond_var, env.subs) (Ok(ret_layout), Ok(cond_layout)) => {
.expect("invalid cond_layout");
// if the hole is a return, then we don't need to merge the two // if the hole is a return, then we don't need to merge the two
// branches together again, we can just immediately return // branches together again, we can just immediately return
let is_terminated = matches!(hole, Stmt::Ret(_)); let is_terminated = matches!(hole, Stmt::Ret(_));
@ -3220,7 +3218,8 @@ pub fn with_hole<'a>(
); );
for (loc_cond, loc_then) in branches.into_iter().rev() { for (loc_cond, loc_then) in branches.into_iter().rev() {
let branching_symbol = possible_reuse_symbol(env, procs, &loc_cond.value); let branching_symbol =
possible_reuse_symbol(env, procs, &loc_cond.value);
let then = with_hole( let then = with_hole(
env, env,
@ -3248,7 +3247,9 @@ pub fn with_hole<'a>(
let layout = layout_cache let layout = layout_cache
.from_var(env.arena, branch_var, env.subs) .from_var(env.arena, branch_var, env.subs)
.unwrap_or_else(|err| panic!("TODO turn fn_var into a RuntimeError {:?}", err)); .unwrap_or_else(|err| {
panic!("TODO turn fn_var into a RuntimeError {:?}", err)
});
let param = Param { let param = Param {
symbol: assigned, symbol: assigned,
@ -3264,6 +3265,10 @@ pub fn with_hole<'a>(
} }
} }
} }
(Err(_), _) => Stmt::RuntimeError("invalid ret_layout"),
(_, Err(_)) => Stmt::RuntimeError("invalid cond_layout"),
}
}
When { When {
cond_var, cond_var,