mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +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
|
||||
);
|
||||
}
|
||||
|
|
|
@ -272,7 +272,12 @@ fn create_llvm_module<'a>(
|
|||
// Uncomment this to see the module's optimized LLVM instruction output:
|
||||
// env.module.print_to_stderr();
|
||||
|
||||
(main_fn_name, delayed_errors.join("\n"), env.module)
|
||||
let delayed_errors = if config.ignore_problems {
|
||||
String::new()
|
||||
} else {
|
||||
delayed_errors.join("\n")
|
||||
};
|
||||
(main_fn_name, delayed_errors, env.module)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue