@@ -1742,21 +1742,28 @@ static ConstraintSystem::TypeMatchResult matchCallArguments(
1742
1742
// inout and @autoclosure.
1743
1743
if (cs.getASTContext().LangOpts.hasFeature(Feature::VariadicGenerics) &&
1744
1744
paramInfo.isVariadicGenericParameter(paramIdx)) {
1745
- auto *paramPackExpansion = paramTy->castTo<PackExpansionType>();
1746
-
1747
- SmallVector<Type, 2> argTypes;
1748
- for (auto argIdx : parameterBindings[paramIdx]) {
1749
- auto argType = argsWithLabels[argIdx].getPlainType();
1750
- argTypes.push_back(argType);
1751
- }
1745
+ // If generic parameter comes from a variadic type declaration it's
1746
+ // possible that it got specialized early and is no longer represented
1747
+ // by a pack expansion type. For example, consider expression -
1748
+ // `Test<Int>(42)` where `Test<each T>` and the initializer
1749
+ // is declared as `init(_: repeat each T)`. Although declaration
1750
+ // based information reports parameter at index 0 as variadic generic
1751
+ // the call site specializes it to `Int`.
1752
+ if (auto *paramPackExpansion = paramTy->getAs<PackExpansionType>()) {
1753
+ SmallVector<Type, 2> argTypes;
1754
+ for (auto argIdx : parameterBindings[paramIdx]) {
1755
+ auto argType = argsWithLabels[argIdx].getPlainType();
1756
+ argTypes.push_back(argType);
1757
+ }
1752
1758
1753
- auto *argPack = PackType::get(cs.getASTContext(), argTypes);
1754
- auto *argPackExpansion = PackExpansionType::get(argPack, argPack);
1759
+ auto *argPack = PackType::get(cs.getASTContext(), argTypes);
1760
+ auto *argPackExpansion = PackExpansionType::get(argPack, argPack);
1755
1761
1756
- cs.addConstraint(
1762
+ cs.addConstraint(
1757
1763
subKind, argPackExpansion, paramPackExpansion,
1758
1764
loc, /*isFavored=*/false);
1759
- continue;
1765
+ continue;
1766
+ }
1760
1767
}
1761
1768
1762
1769
// If type inference from default arguments is enabled, let's
0 commit comments