mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
SIL: Handle ProtocolCompositionType in SubstFunctionTypePatternVisitor
Fixes https://github.com/swiftlang/swift/issues/62061.
This commit is contained in:
@@ -1022,6 +1022,14 @@ AbstractionPattern AbstractionPattern::getDynamicSelfSelfType() const {
|
||||
cast<DynamicSelfType>(getType()).getSelfType());
|
||||
}
|
||||
|
||||
AbstractionPattern
|
||||
AbstractionPattern::getProtocolCompositionMemberType(unsigned argIndex) const {
|
||||
assert(getKind() == Kind::Type);
|
||||
return AbstractionPattern(getGenericSubstitutions(),
|
||||
getGenericSignature(),
|
||||
cast<ProtocolCompositionType>(getType()).getMembers()[argIndex]);
|
||||
}
|
||||
|
||||
AbstractionPattern
|
||||
AbstractionPattern::getParameterizedProtocolArgType(unsigned argIndex) const {
|
||||
assert(getKind() == Kind::Type);
|
||||
@@ -2699,22 +2707,44 @@ public:
|
||||
CanType visitParameterizedProtocolType(CanParameterizedProtocolType ppt,
|
||||
AbstractionPattern pattern) {
|
||||
// Recurse into the arguments of the parameterized protocol.
|
||||
SmallVector<Type, 4> substArgs;
|
||||
auto origPPT = pattern.getAs<ParameterizedProtocolType>();
|
||||
if (!origPPT)
|
||||
return ppt;
|
||||
|
||||
SmallVector<Type, 4> substArgs;
|
||||
for (unsigned i = 0; i < ppt->getArgs().size(); ++i) {
|
||||
auto argTy = ppt.getArgs()[i];
|
||||
auto origArgTy = pattern.getParameterizedProtocolArgType(i);
|
||||
auto substEltTy = visit(argTy, origArgTy);
|
||||
substArgs.push_back(substEltTy);
|
||||
auto substArgTy = visit(argTy, origArgTy);
|
||||
substArgs.push_back(substArgTy);
|
||||
}
|
||||
|
||||
return CanType(ParameterizedProtocolType::get(
|
||||
TC.Context, ppt->getBaseType(), substArgs));
|
||||
}
|
||||
|
||||
CanType visitProtocolCompositionType(CanProtocolCompositionType pct,
|
||||
AbstractionPattern pattern) {
|
||||
// Recurse into the arguments of the protocol composition.
|
||||
auto origPCT = pattern.getAs<ProtocolCompositionType>();
|
||||
if (!origPCT)
|
||||
return pct;
|
||||
|
||||
SmallVector<Type, 4> substMembers;
|
||||
for (unsigned i = 0; i < pct->getMembers().size(); ++i) {
|
||||
auto memberTy = CanType(pct->getMembers()[i]);
|
||||
auto origMemberTy = pattern.getProtocolCompositionMemberType(i);
|
||||
auto substMemberTy = visit(memberTy, origMemberTy);
|
||||
substMembers.push_back(substMemberTy);
|
||||
}
|
||||
|
||||
return CanType(ProtocolCompositionType::get(
|
||||
TC.Context,
|
||||
substMembers,
|
||||
pct->getInverses(),
|
||||
pct->hasExplicitAnyObject()));
|
||||
}
|
||||
|
||||
/// Visit a tuple pattern. Note that, because of vanishing tuples,
|
||||
/// we can't handle this case by matching a tuple type in the
|
||||
/// substituted type; we have to check for a tuple pattern in the
|
||||
|
||||
Reference in New Issue
Block a user