Fix a bug in the casts optimizations.

DynamicCasts was not considering the fact that subclasses of a given class may implement a protocol, even if the class does not implement it.

Swift SVN r27265
This commit is contained in:
Roman Levenstein
2015-04-14 00:17:23 +00:00
parent ec47ebdd3a
commit 1a58b365b7
3 changed files with 24 additions and 5 deletions

View File

@@ -130,6 +130,13 @@ classifyDynamicCastToProtocol(CanType source,
if (auto *CD = source.getClassOrBoundGenericClass()) {
if (canClassOrSuperclassesHaveExtensions(CD, isWholeModuleOpts))
return DynamicCastFeasibility::MaySucceed;
// Derived types may conform to the protocol.
if (!CD->isFinal()) {
// TODO: If it is a private type or internal type and we
// can prove that there are no derived types conforming to a
// protocol, then we can still return WillFail.
return DynamicCastFeasibility::MaySucceed;
}
}
// If the source type is private or target protocol is private,