mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #70457 from slavapestov/parameter-pack-open-type
Fix openType() handling of parameter packs
This commit is contained in:
@@ -969,25 +969,7 @@ Type ConstraintSystem::openUnboundGenericType(GenericTypeDecl *decl,
|
||||
result = DC->mapTypeIntoContext(result);
|
||||
}
|
||||
|
||||
return result.transform([&](Type type) -> Type {
|
||||
// Although generic parameters are declared with just `each`
|
||||
// their interface types introduce a pack expansion which
|
||||
// means that the solver has to extact generic argument type
|
||||
// variable from Pack{repeat ...} and drop that structure to
|
||||
// make sure that generic argument gets inferred to a pack type.
|
||||
if (auto *packTy = type->getAs<PackType>()) {
|
||||
assert(packTy->getNumElements() == 1);
|
||||
auto *expansion = packTy->getElementType(0)->castTo<PackExpansionType>();
|
||||
auto *typeVar = expansion->getPatternType()->castTo<TypeVariableType>();
|
||||
assert(typeVar->getImpl().getGenericParameter() &&
|
||||
typeVar->getImpl().canBindToPack());
|
||||
return typeVar;
|
||||
}
|
||||
|
||||
if (auto *expansion = dyn_cast<PackExpansionType>(type.getPointer()))
|
||||
return openPackExpansionType(expansion, replacements, locator);
|
||||
return type;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
static void checkNestedTypeConstraints(ConstraintSystem &cs, Type type,
|
||||
@@ -1136,18 +1118,6 @@ Type ConstraintSystem::openType(Type type, OpenedTypeMap &replacements,
|
||||
}
|
||||
}
|
||||
|
||||
// While opening variadic generic types that appear in other types
|
||||
// we need to extract generic parameter from Pack{repeat ...} structure
|
||||
// that gets introduced by the interface type, see
|
||||
// \c openUnboundGenericType for more details.
|
||||
if (auto *packTy = type->getAs<PackType>()) {
|
||||
if (auto expansionTy = packTy->unwrapSingletonPackExpansion()) {
|
||||
auto patternTy = expansionTy->getPatternType();
|
||||
if (patternTy->isTypeParameter())
|
||||
return openType(patternTy, replacements, locator);
|
||||
}
|
||||
}
|
||||
|
||||
if (auto *expansion = type->getAs<PackExpansionType>()) {
|
||||
return openPackExpansionType(expansion, replacements, locator);
|
||||
}
|
||||
@@ -4143,6 +4113,14 @@ struct TypeSimplifier {
|
||||
auto countType = expansion->getCountType().transform(
|
||||
TypeSimplifier(CS, GetFixedTypeFn));
|
||||
|
||||
if (!countType->is<PackType>() &&
|
||||
!countType->is<PackArchetypeType>()) {
|
||||
SmallVector<Type, 2> rootParameterPacks;
|
||||
countType->getTypeParameterPacks(rootParameterPacks);
|
||||
if (!rootParameterPacks.empty())
|
||||
countType = rootParameterPacks[0];
|
||||
}
|
||||
|
||||
// If both pattern and count are resolves, let's just return
|
||||
// the pattern type for `transformWithPosition` to take care
|
||||
// of the rest.
|
||||
|
||||
Reference in New Issue
Block a user