From a5f0b69f09266b8b90bf223119c8bd283eaaa9de Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 27 Nov 2023 21:51:31 +0100 Subject: [PATCH] fix dropping the wrong argument for List.map when it captures --- crates/compiler/mono/src/code_gen_help/mod.rs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/compiler/mono/src/code_gen_help/mod.rs b/crates/compiler/mono/src/code_gen_help/mod.rs index 7374cbb2cd5..006bea6cccf 100644 --- a/crates/compiler/mono/src/code_gen_help/mod.rs +++ b/crates/compiler/mono/src/code_gen_help/mod.rs @@ -673,7 +673,25 @@ impl<'a> CallerProc<'a> { let argument_layouts = match capture_layout { None => passed_function.argument_layouts, - Some(_) => &passed_function.argument_layouts[1..], + Some(capture_layout) => { + let capture_layout_index = passed_function.argument_layouts.len() - 1; + + #[cfg(debug_assertions)] + { + let passed_capture_layout = + passed_function.argument_layouts[capture_layout_index]; + let repr = layout_interner.get_repr(passed_capture_layout); + + if let LayoutRepr::LambdaSet(lambda_set) = repr { + assert!(layout_interner + .equiv(capture_layout, lambda_set.runtime_representation())); + } else { + panic!("unexpected layout for capture argument"); + } + } + + &passed_function.argument_layouts[..capture_layout_index] + } }; let capture_symbol = ARG_SYMBOLS[0];