Treat AnyObject conformance for an archetype or existential specially.

These types may not have a conformance for AnyObject explicitly declared,
but being class-bound in some other way is good enough.

<rdar://problem/16818324>

Swift SVN r17581
This commit is contained in:
Jordan Rose
2014-05-06 23:24:14 +00:00
parent baf731271b
commit d9fc1c4fb9

View File

@@ -689,6 +689,12 @@ LookupConformanceResult Module::lookupConformance(Type type,
// An archetype conforms to a protocol if the protocol is listed in the
// archetype's list of conformances.
if (auto archetype = type->getAs<ArchetypeType>()) {
if (protocol->isSpecificProtocol(KnownProtocolKind::AnyObject)) {
if (archetype->requiresClass())
return { nullptr, ConformanceKind::Conforms };
return { nullptr, ConformanceKind::DoesNotConform };
}
for (auto ap : archetype->getConformsTo()) {
if (ap == protocol || ap->inheritsFrom(protocol))
return { nullptr, ConformanceKind::Conforms };
@@ -713,6 +719,15 @@ LookupConformanceResult Module::lookupConformance(Type type,
if (known && !*known)
return { nullptr, ConformanceKind::DoesNotConform };
// Special-case AnyObject, which may not be in the list of conformances.
if (protocol->isSpecificProtocol(KnownProtocolKind::AnyObject)) {
if (type->isClassExistentialType()) {
return { nullptr, known ? ConformanceKind::Conforms
: ConformanceKind::UncheckedConforms };
}
return { nullptr, ConformanceKind::DoesNotConform };
}
// Look for this protocol within the existential's list of conformances.
SmallVector<ProtocolDecl *, 4> protocols;
type->getAnyExistentialTypeProtocols(protocols);