Only permit inheritance of protocol conformance when it is semantically valid.

A protocol conformance of a class A to a protocol P can be inherited
by a subclass B of A unless
  - A requirement of P refers to Self (not an associated type thereof)
  in its signature, 
    + *except* when Self is the result type of the method in P and the
    corresponding witness for A's conformance to B is a DynamicSelf
    method.

Remove the uses of DynamicSelf from the literal protocols, going back
to Self. The fact that the conformances of NSDictionary, NSArray,
NSString, etc. to the corresponding literal protocols use witnesses
that return DynamicSelf makes NSMutableDictionary, NSMutableArray,
NSMutableString, and other subclasses still conform to the
protocol. We also correctly reject attempts to (for example) create an
NSDecimalNumber from a numeric literal, because NSNumber doesn't
provide a suitable factory method by which any subclass can be literal
convertible.



Swift SVN r14204
This commit is contained in:
Doug Gregor
2014-02-21 07:48:28 +00:00
parent e77e43ff4a
commit 926e3711d0
4 changed files with 282 additions and 7 deletions

View File

@@ -697,6 +697,12 @@ LookupConformanceResult Module::lookupConformance(Type type,
return inheritedConformance;
case ConformanceKind::Conforms:
// If the inherited conformance is not in fact inheritable, then
// we're done.
if (!inheritedConformance.getPointer()->isInheritable(resolver)) {
return { nullptr, ConformanceKind::DoesNotConform };
}
// Create inherited conformance below.
break;
}