@@ -117,6 +117,16 @@ static Optional<unsigned> scoreParamAndArgNameTypo(StringRef paramName,
117
117
return dist;
118
118
}
119
119
120
+ static bool isPackExpansionType(Type type) {
121
+ if (type->is<PackExpansionType>())
122
+ return true;
123
+
124
+ if (auto *typeVar = type->getAs<TypeVariableType>())
125
+ return typeVar->getImpl().isPackExpansion();
126
+
127
+ return false;
128
+ }
129
+
120
130
bool constraints::doesMemberRefApplyCurriedSelf(Type baseTy,
121
131
const ValueDecl *decl) {
122
132
assert(decl->getDeclContext()->isTypeContext() &&
@@ -534,8 +544,7 @@ static bool matchCallArgumentsImpl(
534
544
}
535
545
536
546
// Handle variadic parameters.
537
- if (param.isVariadic() ||
538
- param.getPlainType()->is<PackExpansionType>()) {
547
+ if (param.isVariadic() || isPackExpansionType(param.getPlainType())) {
539
548
// Claim the next argument with the name of this parameter.
540
549
auto claimed =
541
550
claimNextNamed(nextArgIdx, paramLabel, ignoreNameMismatch);
@@ -795,8 +804,7 @@ static bool matchCallArgumentsImpl(
795
804
const auto ¶m = params[paramIdx];
796
805
797
806
// Variadic parameters can be unfulfilled.
798
- if (param.isVariadic() ||
799
- param.getPlainType()->is<PackExpansionType>())
807
+ if (param.isVariadic() || isPackExpansionType(param.getPlainType()))
800
808
continue;
801
809
802
810
// Parameters with defaults can be unfulfilled.
@@ -886,7 +894,7 @@ static bool matchCallArgumentsImpl(
886
894
887
895
// Does nothing for variadic tail.
888
896
if ((params[paramIdx].isVariadic() ||
889
- params[paramIdx].getPlainType()->is<PackExpansionType>( )) &&
897
+ isPackExpansionType( params[paramIdx].getPlainType())) &&
890
898
paramBindIdx > 0) {
891
899
assert(args[fromArgIdx].getLabel().empty());
892
900
continue;
@@ -1763,7 +1771,7 @@ static ConstraintSystem::TypeMatchResult matchCallArguments(
1763
1771
// is declared as `init(_: repeat each T)`. Although declaration
1764
1772
// based information reports parameter at index 0 as variadic generic
1765
1773
// the call site specializes it to `Int`.
1766
- if (auto *paramPackExpansion = paramTy->getAs<PackExpansionType>( )) {
1774
+ if (isPackExpansionType(paramTy )) {
1767
1775
SmallVector<Type, 2> argTypes;
1768
1776
for (auto argIdx : parameterBindings[paramIdx]) {
1769
1777
auto argType = argsWithLabels[argIdx].getPlainType();
@@ -1773,9 +1781,7 @@ static ConstraintSystem::TypeMatchResult matchCallArguments(
1773
1781
auto *argPack = PackType::get(cs.getASTContext(), argTypes);
1774
1782
auto *argPackExpansion = PackExpansionType::get(argPack, argPack);
1775
1783
1776
- cs.addConstraint(
1777
- subKind, argPackExpansion, paramPackExpansion,
1778
- loc, /*isFavored=*/false);
1784
+ cs.addConstraint(subKind, argPackExpansion, paramTy, loc);
1779
1785
continue;
1780
1786
}
1781
1787
}
@@ -2081,16 +2087,6 @@ static bool isInPatternMatchingContext(ConstraintLocatorBuilder locator) {
2081
2087
2082
2088
namespace {
2083
2089
2084
- static bool isPackExpansionType(Type type) {
2085
- if (type->is<PackExpansionType>())
2086
- return true;
2087
-
2088
- if (auto *typeVar = type->getAs<TypeVariableType>())
2089
- return typeVar->getImpl().isPackExpansion();
2090
-
2091
- return false;
2092
- }
2093
-
2094
2090
class TupleMatcher {
2095
2091
TupleType *tuple1;
2096
2092
TupleType *tuple2;
@@ -2421,8 +2417,9 @@ static PackType *replaceTypeVariablesWithFreshPacks(ConstraintSystem &cs,
2421
2417
for (unsigned i = 0, e = pack->getNumElements(); i < e; ++i) {
2422
2418
auto *packExpansionElt = pack->getElementType(i)->getAs<PackExpansionType>();
2423
2419
2424
- auto instantiatedPattern = pattern.transformRec([&](Type t) -> Optional<Type> {
2425
- if (t->is<PackExpansionType>())
2420
+ auto instantiatedPattern = pattern.transformRec([&](Type t)
2421
+ -> Optional<Type> {
2422
+ if (isPackExpansionType(t))
2426
2423
return t;
2427
2424
2428
2425
if (auto *typeVar = t->getAs<TypeVariableType>()) {
@@ -2658,8 +2655,7 @@ static bool isSingleTupleParam(ASTContext &ctx,
2658
2655
return false;
2659
2656
2660
2657
const auto ¶m = params.front();
2661
- if ((param.isVariadic() ||
2662
- param.getPlainType()->is<PackExpansionType>()) ||
2658
+ if ((param.isVariadic() || isPackExpansionType(param.getPlainType())) ||
2663
2659
param.isInOut() || param.hasLabel() || param.isIsolated())
2664
2660
return false;
2665
2661
@@ -11033,7 +11029,7 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
11033
11029
11034
11030
// Cannot propagate pack expansion type from context,
11035
11031
// it has to be handled by type matching logic.
11036
- if (contextualTy->is<PackExpansionType>( ))
11032
+ if (isPackExpansionType(contextualTy ))
11037
11033
return false;
11038
11034
11039
11035
// If contextual type has an error, let's wait for inference,
0 commit comments