mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user