mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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
This commit is contained in:
@@ -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<TypeVariableType>()) {
|
||||
auto isParam = [](const Expr *expr) {
|
||||
if (auto *DRE = dyn_cast<DeclRefExpr>(expr)) {
|
||||
|
||||
Reference in New Issue
Block a user