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.

(Also, fix the error that was responsible for breaking
the expr/cast/bridged.swift test.)

<rdar://problem/19813772>

Swift SVN r28034
This commit is contained in:
Chris Willmore
2015-05-01 08:27:19 +00:00
parent f138a84f49
commit 331b570329
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;
}