@@ -1145,17 +1145,22 @@ static bool isArrayDictionarySetOrString(const ASTContext &ctx, Type type) {
1145
1145
return false ;
1146
1146
}
1147
1147
1148
- // / Return the number of elements of parameter tuple type 'tupleTy' that must
1149
- // / be matched to arguments, as opposed to being varargs or having default
1150
- // / values.
1151
- static unsigned tupleTypeRequiredArgCount (TupleType *tupleTy) {
1152
- auto argIsRequired = [&](const TupleTypeElt &elt) {
1153
- return !elt.isVararg () &&
1154
- elt.getDefaultArgKind () == DefaultArgumentKind::None;
1155
- };
1156
- return std::count_if (
1157
- tupleTy->getElements ().begin (), tupleTy->getElements ().end (),
1158
- argIsRequired);
1148
+ // / Given that 'tupleTy' is the argument type of a function that's being
1149
+ // / invoked with a single unlabeled argument, return the type of the parameter
1150
+ // / that matches that argument, or the null type if such a match is impossible.
1151
+ static Type getTupleElementTypeForSingleArgument (TupleType *tupleTy) {
1152
+ Type result;
1153
+ for (auto ¶m : tupleTy->getElements ()) {
1154
+ bool mustClaimArg = !param.isVararg () &&
1155
+ param.getDefaultArgKind () == DefaultArgumentKind::None;
1156
+ bool canClaimArg = !param.hasName ();
1157
+ if (!result && canClaimArg) {
1158
+ result = param.isVararg () ? param.getVarargBaseTy () : param.getType ();
1159
+ } else if (mustClaimArg) {
1160
+ return Type ();
1161
+ }
1162
+ }
1163
+ return result;
1159
1164
}
1160
1165
1161
1166
ConstraintSystem::SolutionKind
@@ -1332,30 +1337,19 @@ ConstraintSystem::matchTypes(Type type1, Type type2, TypeMatchKind kind,
1332
1337
case TypeMatchKind::ArgumentTupleConversion:
1333
1338
if (typeVar1 &&
1334
1339
!typeVar1->getImpl ().literalConformanceProto &&
1335
- kind == TypeMatchKind::ArgumentTupleConversion &&
1336
1340
(flags & TMF_GenerateConstraints) &&
1337
1341
dyn_cast<ParenType>(type1.getPointer ())) {
1338
1342
1339
- auto tupleTy = type2->getAs <TupleType>();
1340
-
1341
- if (tupleTy &&
1342
- !tupleTy->getElements ().empty () &&
1343
- (tupleTy->hasAnyDefaultValues () ||
1344
- tupleTy->getElement (0 ).isVararg ()) &&
1345
- !tupleTy->getElement (0 ).hasName () &&
1346
- tupleTypeRequiredArgCount (tupleTy) <= 1 ) {
1347
-
1348
- // Look through vararg types, if necessary.
1349
- auto tupleElt = tupleTy->getElement (0 );
1350
- auto tupleEltTy = tupleElt.isVararg () ?
1351
- tupleElt.getVarargBaseTy () : tupleElt.getType ();
1352
-
1353
- addConstraint (getConstraintKind (kind),
1354
- typeVar1,
1355
- tupleEltTy,
1356
- getConstraintLocator (locator));
1357
- return SolutionKind::Solved;
1343
+ if (auto tupleTy = type2->getAs <TupleType>()) {
1344
+ if (auto tupleEltTy = getTupleElementTypeForSingleArgument (tupleTy)) {
1345
+ addConstraint (getConstraintKind (kind),
1346
+ typeVar1,
1347
+ tupleEltTy,
1348
+ getConstraintLocator (locator));
1349
+ return SolutionKind::Solved;
1350
+ }
1358
1351
}
1352
+
1359
1353
}
1360
1354
SWIFT_FALLTHROUGH;
1361
1355
0 commit comments