Skip to content

Commit 1022ac7

Browse files
committed
[ConstraintSystem] Check whether extraneous arguments are related to tuple splat
Before recording a generic "extraneous arguments" fix, let's check whether this is a tuple splat with a single parameter.
1 parent 02688a9 commit 1022ac7

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -983,22 +983,24 @@ ConstraintSystem::TypeMatchResult constraints::matchCallArguments(
983983
parameterBindings, locator);
984984
if (constraints::matchCallArguments(
985985
argsWithLabels, params, paramInfo, hasTrailingClosure,
986-
cs.shouldAttemptFixes(), listener, parameterBindings)) {
987-
if (!cs.shouldAttemptFixes())
988-
return cs.getTypeMatchFailure(locator);
989-
990-
if (AllowTupleSplatForSingleParameter::attempt(
991-
cs, argsWithLabels, params, parameterBindings, locator))
992-
return cs.getTypeMatchFailure(locator);
993-
}
986+
cs.shouldAttemptFixes(), listener, parameterBindings))
987+
return cs.getTypeMatchFailure(locator);
994988

995989
auto extraArguments = listener.getExtraneousArguments();
996990
if (!extraArguments.empty()) {
997-
auto *fix = RemoveExtraneousArguments::create(
998-
cs, contextualType, extraArguments, cs.getConstraintLocator(locator));
999-
1000-
if (cs.recordFix(fix, /*impact=*/extraArguments.size() * 2))
1001-
return cs.getTypeMatchFailure(locator);
991+
// First let's see whether this is a situation where a single
992+
// parameter is a tuple, but N distinct arguments were passed in.
993+
if (AllowTupleSplatForSingleParameter::attempt(
994+
cs, argsWithLabels, params, parameterBindings, locator)) {
995+
// Let's produce a generic "extraneous arguments"
996+
// diagnostic otherwise.
997+
auto *fix = RemoveExtraneousArguments::create(
998+
cs, contextualType, extraArguments,
999+
cs.getConstraintLocator(locator));
1000+
1001+
if (cs.recordFix(fix, /*impact=*/extraArguments.size() * 5))
1002+
return cs.getTypeMatchFailure(locator);
1003+
}
10021004
}
10031005
}
10041006

0 commit comments

Comments
 (0)