@@ -837,7 +837,21 @@ Type ConstraintSystem::openUnboundGenericType(GenericTypeDecl *decl,
837
837
result = DC->mapTypeIntoContext (result);
838
838
}
839
839
840
- return result.transform ([&](Type type) {
840
+ return result.transform ([&](Type type) -> Type {
841
+ // Although generic parameters are declared with just `each`
842
+ // their interface types introduce a pack expansion which
843
+ // means that the solver has to extact generic argument type
844
+ // variable from Pack{repeat ...} and drop that structure to
845
+ // make sure that generic argument gets inferred to a pack type.
846
+ if (auto *packTy = type->getAs <PackType>()) {
847
+ assert (packTy->getNumElements () == 1 );
848
+ auto *expansion = packTy->getElementType (0 )->castTo <PackExpansionType>();
849
+ auto *typeVar = expansion->getPatternType ()->castTo <TypeVariableType>();
850
+ assert (typeVar->getImpl ().getGenericParameter () &&
851
+ typeVar->getImpl ().canBindToPack ());
852
+ return typeVar;
853
+ }
854
+
841
855
if (auto *expansion = dyn_cast<PackExpansionType>(type.getPointer ()))
842
856
return openPackExpansionType (expansion, replacements, locator);
843
857
return type;
@@ -990,6 +1004,15 @@ Type ConstraintSystem::openType(Type type, OpenedTypeMap &replacements,
990
1004
}
991
1005
}
992
1006
1007
+ // While opening variadic generic types that appear in other types
1008
+ // we need to extract generic parameter from Pack{repeat ...} structure
1009
+ // that gets introduced by the interface type, see
1010
+ // \c openUnboundGenericType for more details.
1011
+ if (auto *packTy = type->getAs <PackType>()) {
1012
+ if (auto expansion = packTy->unwrapSingletonPackExpansion ())
1013
+ type = expansion->getPatternType ();
1014
+ }
1015
+
993
1016
if (auto *expansion = type->getAs <PackExpansionType>()) {
994
1017
return openPackExpansionType (expansion, replacements, locator);
995
1018
}
0 commit comments