mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
fix bug: incorrect var definition before switch
This commit is contained in:
parent
0ac5a16e86
commit
83fd1de89b
2 changed files with 37 additions and 1 deletions
|
@ -2081,4 +2081,40 @@ mod gen_primitives {
|
||||||
i64
|
i64
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deriv_pow() {
|
||||||
|
// exposed bug with ordering of variable declarations before switch
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
app "test" provides [ main ] to "./platform"
|
||||||
|
|
||||||
|
Expr : [ Ln Expr, Pow Expr Expr, Var Str, Val I64 ]
|
||||||
|
|
||||||
|
count : Expr -> I64
|
||||||
|
count = \expr ->
|
||||||
|
when expr is
|
||||||
|
(Var _) -> 1
|
||||||
|
(Val n) -> n
|
||||||
|
(Pow f g) -> count f + count g
|
||||||
|
(Ln f) -> count f
|
||||||
|
|
||||||
|
pow : Expr, Expr -> Expr
|
||||||
|
pow = \a,b ->
|
||||||
|
when Pair a b is
|
||||||
|
Pair (Val _) (Val _) -> Val -1
|
||||||
|
Pair _ (Val 0) -> Val 1
|
||||||
|
Pair f (Val 1) -> f
|
||||||
|
Pair (Val 0) _ -> Val 0
|
||||||
|
Pair f g -> Pow f g
|
||||||
|
|
||||||
|
main : I64
|
||||||
|
main = count (pow (Var "x") (Var "x"))
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
2,
|
||||||
|
i64
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1533,7 +1533,7 @@ fn decide_to_branching<'a>(
|
||||||
ret_layout,
|
ret_layout,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (symbol, layout, expr) in cond_stores_vec.into_iter() {
|
for (symbol, layout, expr) in cond_stores_vec.into_iter().rev() {
|
||||||
switch = Stmt::Let(symbol, expr, layout, env.arena.alloc(switch));
|
switch = Stmt::Let(symbol, expr, layout, env.arena.alloc(switch));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue