Skip to content

Commit 0aff7c0

Browse files
committed
Produce specialized conformances to AnyObject for bound generic types.
Fixes rdar://31910351 (SR-4750)
1 parent 98aae46 commit 0aff7c0

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/AST/ProtocolConformance.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,13 @@ ProtocolConformanceRef::subst(Type origType,
159159
SmallVector<ProtocolConformance *, 1> lookupResults;
160160
classDecl->lookupConformance(classDecl->getParentModule(), proto,
161161
lookupResults);
162-
return ProtocolConformanceRef(lookupResults.front());
162+
auto *conf = lookupResults.front();
163+
auto subMap = substType->getContextSubstitutionMap(
164+
conf->getDeclContext()->getParentModule(), conf->getDeclContext());
165+
if (!subMap.empty())
166+
conf = substType->getASTContext().getSpecializedConformance(substType,
167+
conf, subMap);
168+
return ProtocolConformanceRef(conf);
163169
}
164170

165171
llvm_unreachable("Invalid conformance substitution");

lib/AST/SubstitutionMap.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ Type SubstitutionMap::lookupSubstitution(CanSubstitutableType type) const {
116116
auto genericParam = cast<GenericTypeParamType>(type);
117117
auto mutableThis = const_cast<SubstitutionMap *>(this);
118118
auto replacementTypes = mutableThis->getReplacementTypes();
119-
auto genericParams = getGenericSignature()->getGenericParams();
119+
auto genericSig = getGenericSignature();
120+
assert(genericSig);
121+
auto genericParams = genericSig->getGenericParams();
120122
auto replacementIndex =
121123
GenericParamKey(genericParam).findIndexIn(genericParams);
122124

@@ -133,7 +135,6 @@ Type SubstitutionMap::lookupSubstitution(CanSubstitutableType type) const {
133135
// The generic parameter may have been made concrete by the generic signature,
134136
// substitute into the concrete type.
135137
ModuleDecl &anyModule = *genericParam->getASTContext().getStdlibModule();
136-
auto genericSig = getGenericSignature();
137138
if (auto concreteType = genericSig->getConcreteType(genericParam, anyModule)){
138139
// Set the replacement type to an error, to block infinite recursion.
139140
replacementType = ErrorType::get(concreteType);

0 commit comments

Comments
 (0)