Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion source/compiler/qsc_rca/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
}
}
Expand Down
46 changes: 46 additions & 0 deletions source/compiler/qsc_rca/src/tests/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,49 @@ fn check_rca_for_call_to_function_that_receives_tuple_with_a_non_tuple_dynamic_a
dynamic_param_applications: <empty>"#]],
);
}

#[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: <empty>"#]],
);
}

#[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: <empty>"#]],
);
}
Loading