mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Pending QOI improvements, reinstate implicit bridging conversions.
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user