Support list initialization of C++ classes that is performed via a constructor call. (#6660)

The general strategy here is to import the constructor with a signature
that directly matches the argument. The intent is that the imported
function will eventually be usable directly as the `ImplicitAs.Convert`
function in a generated `impl`.

For initialization from a tuple, for example `(1, 2)`, we import the
selected constructor with a signature that takes a tuple pattern:

  `fn Class.Class((a: i32, b: i32)) -> Class;`

In order to support that, this PR also adds support in general for tuple
patterns in function signatures. It turns out the implementation was
already very close to allowing this.

Assisted-by: Gemini 3 Pro via Antigravity
This commit is contained in:
Richard Smith
2026-01-27 22:04:21 +00:00
committed by GitHub
parent 9f6e84cc02
commit e69c3fd978
18 changed files with 2151 additions and 1118 deletions
+2 -1
View File
@@ -163,7 +163,8 @@ auto PerformCppOverloadResolution(Context& context, SemIR::LocId loc_id,
CARBON_CHECK(best_viable_fn->Function);
CARBON_CHECK(!best_viable_fn->RewriteKind);
SemIR::InstId result_id = ImportCppFunctionDecl(
context, loc_id, best_viable_fn->Function, arg_exprs.size());
context, loc_id, best_viable_fn->Function,
{.num_params = static_cast<int32_t>(arg_exprs.size())});
if (result_id != SemIR::ErrorInst::InstId) {
CheckCppOverloadAccess(
context, loc_id, best_viable_fn->FoundDecl,