diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index 18565ab217..03ed3d3ec2 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -3896,8 +3896,10 @@ fn make_exception_catching_wrapper<'a, 'ctx, 'env>( let argument_types = match RocReturn::from_layout(env, &return_layout) { RocReturn::Return => roc_function_type.get_param_types(), RocReturn::ByPointer => { + // Our fastcc passes the return pointer as the last parameter. + // Remove the return pointer since we now intend to return the result by value. let mut types = roc_function_type.get_param_types(); - types.remove(0); + types.pop(); types } diff --git a/repl_test/src/tests.rs b/repl_test/src/tests.rs index 5abff88496..84df9024ee 100644 --- a/repl_test/src/tests.rs +++ b/repl_test/src/tests.rs @@ -1094,3 +1094,12 @@ fn box_box_type_alias() { r#"Box.box "bye stacks" : HeapStr"#, ) } + +#[test] +#[cfg(not(feature = "wasm"))] +fn issue_2582_specialize_result_value() { + expect_success( + r#"\x, list -> if x > 0 then List.first list else Ok """#, + r" : Num *, List Str -> Result Str [ ListWasEmpty ]*", + ) +}