@@ -79,15 +79,10 @@ - (NSInteger)code {
79
79
- (NSDictionary *)userInfo {
80
80
auto error = (const SwiftError*)self;
81
81
auto userInfo = error->userInfo .load (SWIFT_MEMORY_ORDER_CONSUME);
82
-
83
- if (userInfo) {
84
- // Don't need to .retain.autorelease since it's immutable.
85
- return (NSDictionary *)userInfo;
86
- } else {
87
- // -[NSError userInfo] never returns nil on OS X 10.8 or later.
88
- NSDictionary *emptyDict = SWIFT_LAZY_CONSTANT (@{});
89
- return emptyDict;
90
- }
82
+ assert (userInfo
83
+ && " Error box used as NSError before initialization" );
84
+ // Don't need to .retain.autorelease since it's immutable.
85
+ return (NSDictionary *)userInfo;
91
86
}
92
87
93
88
- (id )copyWithZone : (NSZone *)zone {
@@ -319,8 +314,11 @@ typedef SWIFT_CC(swift)
319
314
static id _swift_bridgeErrorToNSError_(SwiftError *errorObject) {
320
315
auto ns = reinterpret_cast <NSError *>(errorObject);
321
316
322
- // If we already have a domain set, then we've already initialized.
323
- if (errorObject->domain .load (SWIFT_MEMORY_ORDER_CONSUME))
317
+ // If we already have a domain and userInfo set, then we've already
318
+ // initialized.
319
+ // FIXME: This might be overly strict; can we look only at the domain?
320
+ if (errorObject->domain .load (std::memory_order_acquire) &&
321
+ errorObject->userInfo .load (std::memory_order_acquire))
324
322
return ns;
325
323
326
324
// Otherwise, calculate the domain and code (TODO: and user info), and
@@ -334,6 +332,10 @@ static id _swift_bridgeErrorToNSError_(SwiftError *errorObject) {
334
332
NSDictionary *userInfo =
335
333
swift_stdlib_getErrorUserInfoNSDictionary (value, type, witness);
336
334
335
+ // Never produce an empty userInfo dictionary.
336
+ if (!userInfo)
337
+ userInfo = SWIFT_LAZY_CONSTANT (@{});
338
+
337
339
// The error code shouldn't change, so we can store it blindly, even if
338
340
// somebody beat us to it. The store can be relaxed, since we'll do a
339
341
// store(release) of the domain last thing to publish the initialized
0 commit comments