diff --git a/source/compiler/qsc_rca/src/core.rs b/source/compiler/qsc_rca/src/core.rs index 7aca8f19d2..6d55ae3d76 100644 --- a/source/compiler/qsc_rca/src/core.rs +++ b/source/compiler/qsc_rca/src/core.rs @@ -2604,7 +2604,21 @@ fn map_input_pattern_to_input_expressions( // All elements in the pattern map to the same expression. // This is one of the boundaries where we can lose specific information since we are "unpacking" the // tuple represented by a single expression. - vec![expr_id.expr; pats.len()] + let pats_len = if skip_ahead.is_some() { + // When skip_ahead is not None we know we are processing a lambda, so check if pattern is itself a tuple. + // If it is, that is the length we need to use rather than the original one. + if let PatKind::Tuple(pats) = + &package_store.get_pat((pat_id.package, pats[0]).into()).kind + { + pats.len() + } else { + pats.len() + } + } else { + pats.len() + }; + + vec![expr_id.expr; pats_len] } } } diff --git a/source/compiler/qsc_rca/src/tests/calls.rs b/source/compiler/qsc_rca/src/tests/calls.rs index 601cc2a476..44eb31e870 100644 --- a/source/compiler/qsc_rca/src/tests/calls.rs +++ b/source/compiler/qsc_rca/src/tests/calls.rs @@ -325,3 +325,49 @@ fn check_rca_for_call_to_function_that_receives_tuple_with_a_non_tuple_dynamic_a dynamic_param_applications: "#]], ); } + +#[test] +fn check_rca_for_call_to_function_passed_single_tuple_variable_for_multiple_args() { + let mut compilation_context = CompilationContext::default(); + compilation_context.update( + r#" + use q = Qubit(); + let x = (if MResetX(q) == One { 1 } else { 0 }, 2, 3); + operation foo(a : Int, b : Int, c : Int) : Int { a + b + c }; + foo(x) + "#, + ); + let package_store_compute_properties = compilation_context.get_compute_properties(); + check_last_statement_compute_properties( + package_store_compute_properties, + &expect![[r#" + ApplicationsGeneratorSet: + inherent: Quantum: QuantumProperties: + runtime_features: RuntimeFeatureFlags(UseOfDynamicBool | UseOfDynamicInt) + value_kind: Element(Dynamic) + dynamic_param_applications: "#]], + ); +} + +#[test] +fn check_rca_for_call_to_lambda_passed_single_tuple_variable_for_multiple_args() { + let mut compilation_context = CompilationContext::default(); + compilation_context.update( + r#" + use q = Qubit(); + let x = (if MResetX(q) == One { 1 } else { 0 }, 2, 3); + let lambda = (a, b, c) -> { a + b + c }; + lambda(x) + "#, + ); + let package_store_compute_properties = compilation_context.get_compute_properties(); + check_last_statement_compute_properties( + package_store_compute_properties, + &expect![[r#" + ApplicationsGeneratorSet: + inherent: Quantum: QuantumProperties: + runtime_features: RuntimeFeatureFlags(UseOfDynamicBool | UseOfDynamicInt) + value_kind: Element(Dynamic) + dynamic_param_applications: "#]], + ); +}