When performing an "is" check that involves bridging, do a full conditional check.

Previously, we were only changing whether the object was of the right
type, and not performing a deep check that (for example) the
underlying array contained NSStrings for an "is String[]". Fixes the
rest of <rdar://problem/16972956>.


Swift SVN r18728
This commit is contained in:
Doug Gregor
2014-06-06 04:22:45 +00:00
parent 0cd44d174f
commit 08be461122
2 changed files with 43 additions and 26 deletions

View File

@@ -2372,10 +2372,14 @@ namespace {
SmallVector<Type, 2> toOptionals;
auto toValueType = plumbOptionals(toType, toOptionals);
// If we have an imbalance of optionals, handle this as a checked cast
// followed by a getLogicValue.
// If we have an imbalance of optionals, an array downcast, or
// are bridging through an Objective-C class, handle this as a
// checked cast followed by a getLogicValue.
if (fromOptionals.size() != toOptionals.size() ||
castKind == CheckedCastKind::ArrayDowncast) {
castKind == CheckedCastKind::ArrayDowncast ||
tc.getDynamicBridgedThroughObjCClass(cs.DC,
fromValueType,
toValueType)) {
auto toOptType = OptionalType::get(toType);
ConditionalCheckedCastExpr *cast
= new (tc.Context) ConditionalCheckedCastExpr(
@@ -2396,28 +2400,6 @@ namespace {
cs.getConstraintLocator(expr));
}
// Allow for bridging of a value type through a class type.
if (auto classType = tc.getDynamicBridgedThroughObjCClass(cs.DC,
fromValueType,
toValueType)) {
// Rebuild classType with all of the optionals in toOptionals.
for (unsigned i = toOptionals.size(); i > 0; --i) {
// Figure out the kind of this optional.
OptionalTypeKind kind;
toOptionals[i-1]->getAnyOptionalObjectType(kind);
classType = OptionalType::get(kind, classType);
}
// The actual check is against the class type through which we're
// bridging.
expr->getCastTypeLoc().setType(classType, /*validated=*/true);
// FIXME: We actually need to perform a checked cast, then call
// bridgeFromObjectiveC to try to perform the bridge, then check whether
// that optional has a value.
}
return expr;
}