mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
Merge pull request #3616 from rtfeldman/i3614
Compile branches in the presence of degenerate patterns
This commit is contained in:
commit
d212dffa1a
14 changed files with 210 additions and 66 deletions
|
@ -3651,7 +3651,25 @@ fn shared_pattern_variable_in_when_branches() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "TODO currently fails in alias analysis because `B y` does not introduce `x`"]
|
||||
#[cfg(any(feature = "gen-llvm"))]
|
||||
fn symbol_not_bound_in_all_patterns_runs_when_no_bound_symbol_used() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
f = \t -> when t is
|
||||
A x | B y -> 31u8
|
||||
|
||||
{a: f (A 15u8), b: f (B 15u8)}
|
||||
"#
|
||||
),
|
||||
31u8,
|
||||
u8,
|
||||
|x| x,
|
||||
true // allow errors
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn symbol_not_bound_in_all_patterns_runs_when_bound_pattern_reached() {
|
||||
assert_evals_to!(
|
||||
|
@ -3662,6 +3680,28 @@ fn symbol_not_bound_in_all_patterns_runs_when_bound_pattern_reached() {
|
|||
"#
|
||||
),
|
||||
15u8,
|
||||
u8
|
||||
u8,
|
||||
|x| x,
|
||||
true // allow errors
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
#[should_panic(
|
||||
expected = r#"Roc failed with message: "Hit a branch pattern that does not bind all symbols its body needs"#
|
||||
)]
|
||||
fn runtime_error_when_degenerate_pattern_reached() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when B 15u8 is
|
||||
A x | B y -> x + 5u8
|
||||
"#
|
||||
),
|
||||
15u8,
|
||||
u8,
|
||||
|x| x,
|
||||
true // allow errors
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue