From a0835e7e735d94d5ba38aff36f1f78c2cfabc365 Mon Sep 17 00:00:00 2001 From: Pavel Yaskevich Date: Tue, 9 Dec 2025 16:52:41 -0800 Subject: [PATCH] [Diagnostics] Don't attempt to synthesize arguments when destructuring a single tuple argument results in an overrun If arguments are represented by a single tuple it's possible that the issue is not about missing parameters but instead about tuple destructuring. Fix `fixMissingArguments` to check for overruns after destructuring and stop if that produces more arguments then parameters because such situations are better diagnosed as a general conversion failure rather than a missing argument(s) problem. Resolves: rdar://159408715 (cherry picked from commit 1f887202e1e973d93649c75d633ef70b64d7177a) --- lib/Sema/CSSimplify.cpp | 6 ++++++ .../fixMissingArguments-ef29fe.swift | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) rename validation-test/{compiler_crashers => compiler_crashers_fixed}/fixMissingArguments-ef29fe.swift (85%) diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index 1df197d2f6400..70cd4063db32a 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -2747,6 +2747,12 @@ static bool fixMissingArguments(ConstraintSystem &cs, ASTNode anchor, args.pop_back(); for (const auto &elt : tuple->getElements()) args.emplace_back(elt.getType(), elt.getName()); + + // If unpacking a tuple results in more arguments than parameters + // it would be diagnosed as a general mismatch because it's unclear + // whether it's a problem with missing or extraneous parameters. + if (args.size() > params.size()) + return true; } else if (auto *typeVar = argType->getAs()) { auto isParam = [](const Expr *expr) { if (auto *DRE = dyn_cast(expr)) { diff --git a/validation-test/compiler_crashers/fixMissingArguments-ef29fe.swift b/validation-test/compiler_crashers_fixed/fixMissingArguments-ef29fe.swift similarity index 85% rename from validation-test/compiler_crashers/fixMissingArguments-ef29fe.swift rename to validation-test/compiler_crashers_fixed/fixMissingArguments-ef29fe.swift index 17033d595e488..07a7e52b86f9c 100644 --- a/validation-test/compiler_crashers/fixMissingArguments-ef29fe.swift +++ b/validation-test/compiler_crashers_fixed/fixMissingArguments-ef29fe.swift @@ -1,4 +1,4 @@ // {"kind":"typecheck","languageMode":6,"signature":"fixMissingArguments(swift::constraints::ConstraintSystem&, swift::ASTNode, llvm::SmallVectorImpl&, llvm::ArrayRef, unsigned int, swift::constraints::ConstraintLocatorBuilder)","signatureAssert":"Assertion failed: (Index < Length && \"Invalid index!\"), function operator[]"} -// RUN: not --crash %target-swift-frontend -typecheck -swift-version 6 %s +// RUN: not %target-swift-frontend -typecheck -swift-version 6 %s func a((Int, Int, Int)) a > { b, c in