Sema: Allow ErrorType-conforming types to be explicitly coerced 'as NSError'.

Swift SVN r26993
This commit is contained in:
Joe Groff
2015-04-04 22:38:04 +00:00
parent a15d93ff09
commit 66ae68bcc3
12 changed files with 127 additions and 18 deletions

View File

@@ -1785,6 +1785,13 @@ ConstraintSystem::matchTypes(Type type1, Type type2, TypeMatchKind kind,
allowsBridgingFromObjC(TC, DC, type2)) {
conversionsOrFixes.push_back(ConversionRestrictionKind::BridgeFromObjC);
}
// Bridging from an ErrorType to an Objective-C NSError.
auto errorType = TC.Context.getProtocol(KnownProtocolKind::_ErrorType);
if (TC.conformsToProtocol(type1, errorType, DC, /*expr*/ true)
&& type2->isEqual(TC.getNSErrorType(DC))) {
conversionsOrFixes.push_back(ConversionRestrictionKind::BridgeToNSError);
}
}
// Pointer arguments can be converted from pointer-compatible types.
@@ -4160,6 +4167,16 @@ ConstraintSystem::simplifyRestrictedConstraint(ConversionRestrictionKind restric
locator);
}
case ConversionRestrictionKind::BridgeToNSError: {
increaseScore(SK_UserConversion); // FIXME: Use separate score kind?
// The input type must be an ErrorType subtype.
auto errorType = TC.Context.getProtocol(KnownProtocolKind::_ErrorType)
->getDeclaredType();
return matchTypes(type1, errorType, TypeMatchKind::Subtype, subFlags,
locator);
}
// T' < U and T a toll-free-bridged to T' ===> T' <c U
case ConversionRestrictionKind::CFTollFreeBridgeToObjC: {
increaseScore(SK_UserConversion); // FIXME: Use separate score kind?