From d9e9c28889e65ba8f960909738e75195998f67b0 Mon Sep 17 00:00:00 2001 From: Brendan Hansknecht Date: Sun, 27 Feb 2022 00:45:51 -0800 Subject: [PATCH] add error test case --- compiler/can/src/builtins.rs | 2 +- compiler/test_gen/src/gen_list.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index 550c7d0d0f..dbc5063359 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -2326,7 +2326,7 @@ fn list_replace(symbol: Symbol, var_store: &mut VarStore) -> Def { // Otherwise, return the list unmodified. let body = If { cond_var: bool_var, - branch_var: var_store.fresh(), + branch_var: ret_result_var, branches: vec![( // if-condition no_region( diff --git a/compiler/test_gen/src/gen_list.rs b/compiler/test_gen/src/gen_list.rs index ba4cce5362..ac34090e7d 100644 --- a/compiler/test_gen/src/gen_list.rs +++ b/compiler/test_gen/src/gen_list.rs @@ -1780,6 +1780,23 @@ fn replace_unique_int_list() { ); } +#[test] +#[cfg(any(feature = "gen-llvm"))] +fn replace_unique_int_list_out_of_bounds() { + assert_evals_to!( + indoc!( + r#" + result = List.replace [ 12, 9, 7, 1, 5 ] 5 33 + when result is + Ok {value} -> value + Err OutOfBounds -> -1 + "# + ), + -1, + i64 + ); +} + #[test] #[cfg(any(feature = "gen-llvm"))] fn replace_unique_int_list_get_old_value() {