SE-0072: Fully eliminate implicit bridging conversions from Swift

Per Swift Evolution proposal SE-0072, these changes prevent the compiler from introducing implicit bridging conversions during type checking.
This commit is contained in:
Joe Pamer
2016-05-05 19:36:33 -07:00
parent 9435633f40
commit 3b4d98445e
14 changed files with 80 additions and 84 deletions

View File

@@ -1709,33 +1709,27 @@ ConstraintSystem::matchTypes(Type type1, Type type2, TypeMatchKind kind,
// Bridging from a value type to an Objective-C class type.
// FIXME: Banned for operator parameters, like user conversions are.
// NOTE: The plan for <rdar://problem/18311362> was to make such bridging
// conversions illegal except when explicitly converting with the 'as'
// operator. But using a String to subscript an [NSObject : AnyObject] is
// sufficiently common due to bridging that disallowing such conversions is
// not yet feasible, and a more targeted fix in the type checker is hard to
// justify.
if (type1->isPotentiallyBridgedValueType() &&
type1->getAnyNominal()
!= TC.Context.getImplicitlyUnwrappedOptionalDecl() &&
!(flags & TMF_ApplyingOperatorParameter)) {
auto isBridgeableTargetType = type2->isBridgeableObjectType();
// Allow bridged conversions to CVarArg through NSObject.
if (!isBridgeableTargetType && type2->isExistentialType()) {
if (auto nominalType = type2->getAs<NominalType>())
isBridgeableTargetType = nominalType->getDecl()->getName() ==
TC.Context.Id_CVarArg;
}
if (isBridgeableTargetType && TC.getBridgedToObjC(DC, type1)) {
conversionsOrFixes.push_back(ConversionRestrictionKind::BridgeToObjC);
}
}
if (kind == TypeMatchKind::ExplicitConversion) {
if (type1->isPotentiallyBridgedValueType() &&
type1->getAnyNominal()
!= TC.Context.getImplicitlyUnwrappedOptionalDecl() &&
!(flags & TMF_ApplyingOperatorParameter)) {
auto isBridgeableTargetType = type2->isBridgeableObjectType();
// Allow bridged conversions to CVarArg through NSObject.
if (!isBridgeableTargetType && type2->isExistentialType()) {
if (auto nominalType = type2->getAs<NominalType>())
isBridgeableTargetType = nominalType->getDecl()->getName() ==
TC.Context.Id_CVarArg;
}
if (isBridgeableTargetType && TC.getBridgedToObjC(DC, type1)) {
conversionsOrFixes.push_back(ConversionRestrictionKind::BridgeToObjC);
}
}
// Bridging from an Objective-C class type to a value type.
// Note that specifically require a class or class-constrained archetype
// here, because archetypes cannot be bridged.