mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
feat(mono): return Stmt::RuntimeError on bad layouts for If
This commit is contained in:
parent
16542f0e1e
commit
39d39c218f
1 changed files with 109 additions and 104 deletions
|
@ -3150,13 +3150,11 @@ pub fn with_hole<'a>(
|
|||
branches,
|
||||
final_else,
|
||||
} => {
|
||||
let ret_layout = layout_cache
|
||||
.from_var(env.arena, branch_var, env.subs)
|
||||
.expect("invalid ret_layout");
|
||||
let cond_layout = layout_cache
|
||||
.from_var(env.arena, cond_var, env.subs)
|
||||
.expect("invalid cond_layout");
|
||||
|
||||
match (
|
||||
layout_cache.from_var(env.arena, branch_var, env.subs),
|
||||
layout_cache.from_var(env.arena, cond_var, env.subs),
|
||||
) {
|
||||
(Ok(ret_layout), Ok(cond_layout)) => {
|
||||
// if the hole is a return, then we don't need to merge the two
|
||||
// branches together again, we can just immediately return
|
||||
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() {
|
||||
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(
|
||||
env,
|
||||
|
@ -3248,7 +3247,9 @@ pub fn with_hole<'a>(
|
|||
|
||||
let layout = layout_cache
|
||||
.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 {
|
||||
symbol: assigned,
|
||||
|
@ -3264,6 +3265,10 @@ pub fn with_hole<'a>(
|
|||
}
|
||||
}
|
||||
}
|
||||
(Err(_), _) => Stmt::RuntimeError("invalid ret_layout"),
|
||||
(_, Err(_)) => Stmt::RuntimeError("invalid cond_layout"),
|
||||
}
|
||||
}
|
||||
|
||||
When {
|
||||
cond_var,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue