Skip to content

Commit 2e34ea2

Browse files
authored
Merge pull request #861 from ikesyo/3.1-error-localizeddescription-impl
2 parents d33b30a + d1c3a63 commit 2e34ea2

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

Foundation.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@
315315
BDFDF0A71DFF5B3E00C04CC5 /* TestNSPersonNameComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDFDF0A61DFF5B3E00C04CC5 /* TestNSPersonNameComponents.swift */; };
316316
BF8E65311DC3B3CB005AB5C3 /* TestNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF8E65301DC3B3CB005AB5C3 /* TestNotification.swift */; };
317317
CC5249C01D341D23007CB54D /* TestUnitConverter.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC5249BF1D341D23007CB54D /* TestUnitConverter.swift */; };
318+
CD1C7F7D1E303B47008E331C /* TestNSError.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1C7F7C1E303B47008E331C /* TestNSError.swift */; };
318319
CE19A88C1C23AA2300B4CB6A /* NSStringTestData.txt in Resources */ = {isa = PBXBuildFile; fileRef = CE19A88B1C23AA2300B4CB6A /* NSStringTestData.txt */; };
319320
D31302011C30CEA900295652 /* NSConcreteValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = D31302001C30CEA900295652 /* NSConcreteValue.swift */; };
320321
D370696E1C394FBF00295652 /* NSKeyedUnarchiver-RangeTest.plist in Resources */ = {isa = PBXBuildFile; fileRef = D370696D1C394FBF00295652 /* NSKeyedUnarchiver-RangeTest.plist */; };
@@ -759,6 +760,7 @@
759760
C2A9D75B1C15C08B00993803 /* TestNSUUID.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSUUID.swift; sourceTree = "<group>"; };
760761
C93559281C12C49F009FD6A9 /* TestNSAffineTransform.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSAffineTransform.swift; sourceTree = "<group>"; };
761762
CC5249BF1D341D23007CB54D /* TestUnitConverter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestUnitConverter.swift; sourceTree = "<group>"; };
763+
CD1C7F7C1E303B47008E331C /* TestNSError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSError.swift; sourceTree = "<group>"; };
762764
CE19A88B1C23AA2300B4CB6A /* NSStringTestData.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = NSStringTestData.txt; sourceTree = "<group>"; };
763765
D3047AEB1C38BC3300295652 /* TestNSValue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSValue.swift; sourceTree = "<group>"; };
764766
D31302001C30CEA900295652 /* NSConcreteValue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSConcreteValue.swift; sourceTree = "<group>"; };
@@ -1395,6 +1397,7 @@
13951397
EA54A6FA1DB16D53009E0809 /* TestObjCRuntime.swift */,
13961398
BF8E65301DC3B3CB005AB5C3 /* TestNotification.swift */,
13971399
BDFDF0A61DFF5B3E00C04CC5 /* TestNSPersonNameComponents.swift */,
1400+
CD1C7F7C1E303B47008E331C /* TestNSError.swift */,
13981401
);
13991402
name = Tests;
14001403
sourceTree = "<group>";
@@ -2275,6 +2278,7 @@
22752278
5B13B3511C582D4C00651CE2 /* TestNSByteCountFormatter.swift in Sources */,
22762279
BDFDF0A71DFF5B3E00C04CC5 /* TestNSPersonNameComponents.swift in Sources */,
22772280
5B13B3501C582D4C00651CE2 /* TestUtils.swift in Sources */,
2281+
CD1C7F7D1E303B47008E331C /* TestNSError.swift in Sources */,
22782282
294E3C1D1CC5E19300E4F44C /* TestNSAttributedString.swift in Sources */,
22792283
5B13B3431C582D4C00651CE2 /* TestNSScanner.swift in Sources */,
22802284
5B13B3401C582D4C00651CE2 /* TestNSRange.swift in Sources */,

Foundation/NSError.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ public extension Error where Self : CustomNSError {
288288
public extension Error {
289289
/// Retrieve the localized description for this error.
290290
var localizedDescription: String {
291-
return NSError(domain: _domain, code: _code, userInfo: nil).localizedDescription
291+
let defaultUserInfo = _swift_Foundation_getErrorDefaultUserInfo(self) as! [String : Any]
292+
return NSError(domain: _domain, code: _code, userInfo: defaultUserInfo).localizedDescription
292293
}
293294
}
294295

TestFoundation/TestNSError.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// This source file is part of the Swift.org open source project
2+
//
3+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
4+
// Licensed under Apache License v2.0 with Runtime Library Exception
5+
//
6+
// See https://swift.org/LICENSE.txt for license information
7+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
8+
//
9+
10+
11+
#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
12+
import Foundation
13+
import XCTest
14+
#else
15+
import SwiftFoundation
16+
import SwiftXCTest
17+
#endif
18+
19+
20+
class TestNSError : XCTestCase {
21+
22+
static var allTests: [(String, (TestNSError) -> () throws -> Void)] {
23+
return [
24+
("test_LocalizedError_errorDescription", test_LocalizedError_errorDescription),
25+
]
26+
}
27+
28+
func test_LocalizedError_errorDescription() {
29+
struct Error : LocalizedError {
30+
var errorDescription: String? { return "error description" }
31+
}
32+
33+
let error = Error()
34+
XCTAssertEqual(error.localizedDescription, "error description")
35+
}
36+
}

TestFoundation/main.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ XCTMain([
3434
testCase(TestNSDateFormatter.allTests),
3535
testCase(TestNSDecimal.allTests),
3636
testCase(TestNSDictionary.allTests),
37+
testCase(TestNSError.allTests),
3738
testCase(TestNSFileManager.allTests),
3839
testCase(TestNSGeometry.allTests),
3940
testCase(TestNSHTTPCookie.allTests),

0 commit comments

Comments
 (0)