[SE-0112] Add error protocols LocalizedError, RecoverableError, CustomNSError

An error type can conform to one or more of these new protocols to
customize its behavior and representation. From an implementation
standpoint, the protocol conformances are used to fill in the
user-info dictionary in NSError to interoperate with the Cocoa
error-handling system.

There are a few outstanding problems with this implementation,
although it is fully functional:
  * Population of the userInfo dictionary is currently eager; we
  should use user info providers on platforms where they are
  available.
  * At present, the Swift dynamic casting machinery is unable to unbox a
  _SwiftNativeNSError when trying to cast from it to (e.g.) an
  existential, which makes it impossible to retrieve the
  RecoverableError from the NSError. Instead, just capture the original
  error---hey, they're supposed to be value types anyway!---and use that
  to implement the entry points for the informal
  NSErrorRecoveryAttempting protocol.

This is part (1) of the proposal solution.
This commit is contained in:
Doug Gregor
2016-07-01 16:34:59 -07:00
parent abf73d3bee
commit b0f9317765
5 changed files with 396 additions and 13 deletions

View File

@@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#import <Foundation/Foundation.h>
#include <objc/message.h>
#include "swift/Runtime/Config.h"
@@ -118,3 +119,12 @@ NS_Swift_NSKeyedUnarchiver_unarchiveObjectWithData(
return [result retain];
}
// -- NSError
SWIFT_CC(swift)
extern "C" void
NS_Swift_performErrorRecoverySelector(_Nullable id delegate,
SEL selector,
BOOL success,
void * _Nullable contextInfo) {
objc_msgSend(delegate, selector, success, contextInfo);
}