Pending QOI improvements, reinstate implicit bridging conversions.

This commit is contained in:
Joe Pamer
2016-05-19 20:41:21 -07:00
parent 3e20817f8c
commit 455aa0523d
2 changed files with 42 additions and 36 deletions

View File

@@ -1709,27 +1709,33 @@ 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.
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);
}
// 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) {
// 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.