Remove reverse subtype constraint between Objective-C classes when type

checking checked cast via bridging. It prevented bridging upcasts using
'as!' from typechecking; we should emit an 'as!'->'as' warning instead.

Also, use ExplicitConversion constraint instead of Conversion when
determining whether a checked cast can be carried out unconditionally.
This matches the constraint used after applying the 'as!'->'as' fixit.

<rdar://problem/19813772>

Swift SVN r28028
This commit is contained in:
Chris Willmore
2015-05-01 06:21:50 +00:00
parent fbbd834493
commit 7d413057aa
4 changed files with 24 additions and 16 deletions

View File

@@ -2518,22 +2518,15 @@ ConstraintSystem::simplifyCheckedCastConstraint(
case CheckedCastKind::BridgeFromObjectiveC: {
// This existential-to-concrete cast might bridge through an Objective-C
// class type.
if (auto classType = TC.getDynamicBridgedThroughObjCClass(DC, true,
fromType,
toType)) {
// The class we're bridging through must be a subtype of the type we're
// coming from.
addConstraint(ConstraintKind::Subtype, classType, fromType,
getConstraintLocator(locator));
return SolutionKind::Solved;
}
Type objCClass = TC.getDynamicBridgedThroughObjCClass(DC, true,
fromType,
toType);
assert(objCClass && "Type must be bridged");
addConstraint(ConstraintKind::Subtype, objCClass, fromType,
getConstraintLocator(locator));
(void)objCClass;
// Otherwise no constraint is necessary; as long as both objCClass and
// fromType are Objective-C types, they can't have any open type variables,
// and conversion between unrelated classes will be diagnosed in
// typeCheckCheckedCast.
return SolutionKind::Solved;
}