fix #333: bug with symbol in if condition

This commit is contained in:
Folkert 2020-12-25 20:13:42 +01:00
parent 917ec9c44c
commit 2bcaf3921f
2 changed files with 21 additions and 6 deletions

View file

@ -1732,4 +1732,20 @@ mod gen_primitives {
|_| 0 |_| 0
); );
} }
#[test]
fn hof_conditional() {
// exposed issue with the if condition being just a symbol
assert_evals_to!(
indoc!(
r#"
passTrue = \f -> f True
passTrue (\trueVal -> if trueVal then False else True)
"#
),
0,
u8
);
}
} }

View file

@ -3678,7 +3678,7 @@ pub fn from_can<'a>(
let mut stmt = from_can(env, branch_var, final_else.value, procs, layout_cache); let mut stmt = from_can(env, branch_var, final_else.value, procs, layout_cache);
for (loc_cond, loc_then) in branches.into_iter().rev() { for (loc_cond, loc_then) in branches.into_iter().rev() {
let branching_symbol = env.unique_symbol(); let branching_symbol = possible_reuse_symbol(env, procs, &loc_cond.value);
let then = from_can(env, branch_var, loc_then.value, procs, layout_cache); let then = from_can(env, branch_var, loc_then.value, procs, layout_cache);
stmt = Stmt::Cond { stmt = Stmt::Cond {
@ -3691,15 +3691,14 @@ pub fn from_can<'a>(
ret_layout: ret_layout.clone(), ret_layout: ret_layout.clone(),
}; };
// add condition stmt = assign_to_symbol(
stmt = with_hole(
env, env,
loc_cond.value,
cond_var,
procs, procs,
layout_cache, layout_cache,
cond_var,
loc_cond,
branching_symbol, branching_symbol,
env.arena.alloc(stmt), stmt,
); );
} }