Produce specialized conformances to AnyObject for bound generic types.

Fixes rdar://31910351 (SR-4750)
This commit is contained in:
Roman Levenstein
2017-05-01 17:53:57 -07:00
parent 98aae46ae6
commit 0aff7c0c78
2 changed files with 10 additions and 3 deletions

View File

@@ -159,7 +159,13 @@ ProtocolConformanceRef::subst(Type origType,
SmallVector<ProtocolConformance *, 1> lookupResults;
classDecl->lookupConformance(classDecl->getParentModule(), proto,
lookupResults);
return ProtocolConformanceRef(lookupResults.front());
auto *conf = lookupResults.front();
auto subMap = substType->getContextSubstitutionMap(
conf->getDeclContext()->getParentModule(), conf->getDeclContext());
if (!subMap.empty())
conf = substType->getASTContext().getSpecializedConformance(substType,
conf, subMap);
return ProtocolConformanceRef(conf);
}
llvm_unreachable("Invalid conformance substitution");

View File

@@ -116,7 +116,9 @@ Type SubstitutionMap::lookupSubstitution(CanSubstitutableType type) const {
auto genericParam = cast<GenericTypeParamType>(type);
auto mutableThis = const_cast<SubstitutionMap *>(this);
auto replacementTypes = mutableThis->getReplacementTypes();
auto genericParams = getGenericSignature()->getGenericParams();
auto genericSig = getGenericSignature();
assert(genericSig);
auto genericParams = genericSig->getGenericParams();
auto replacementIndex =
GenericParamKey(genericParam).findIndexIn(genericParams);
@@ -133,7 +135,6 @@ Type SubstitutionMap::lookupSubstitution(CanSubstitutableType type) const {
// The generic parameter may have been made concrete by the generic signature,
// substitute into the concrete type.
ModuleDecl &anyModule = *genericParam->getASTContext().getStdlibModule();
auto genericSig = getGenericSignature();
if (auto concreteType = genericSig->getConcreteType(genericParam, anyModule)){
// Set the replacement type to an error, to block infinite recursion.
replacementType = ErrorType::get(concreteType);