Crash at runtime rather than panicking when if condition is erroneous

Closes #5318
This commit is contained in:
Ayaz Hafiz 2023-05-01 15:48:05 -05:00
parent cdf8677dfb
commit a9975b1f7f
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
4 changed files with 31 additions and 9 deletions

View file

@ -0,0 +1,3 @@
procedure Test.0 ():
let Test.2 : Str = "Erroneous: invalid condition type in if expression";
Crash Test.2

View file

@ -76,7 +76,7 @@ fn promote_expr_to_module(src: &str) -> String {
buffer
}
fn compiles_to_ir(test_name: &str, src: &str, mode: &str, no_check: bool) {
fn compiles_to_ir(test_name: &str, src: &str, mode: &str, allow_type_errors: bool, no_check: bool) {
use roc_packaging::cache::RocCacheDir;
use std::path::PathBuf;
@ -146,7 +146,7 @@ fn compiles_to_ir(test_name: &str, src: &str, mode: &str, no_check: bool) {
println!("Ignoring {} canonicalization problems", can_problems.len());
}
assert!(type_problems.is_empty());
assert!(allow_type_errors || type_problems.is_empty());
let main_fn_symbol = exposed_to_host.top_level_values.keys().copied().next();
@ -2888,3 +2888,14 @@ fn layout_cache_structure_with_multiple_recursive_structures() {
"#
)
}
#[mono_test(allow_type_errors = "true")]
fn error_on_erroneous_condition() {
indoc!(
r#"
app "test" provides [main] to "./platform"
main = if True then 1 else 2
"#
)
}