mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user