Skip to content

Commit aa0cfa3

Browse files
committed
Better default domain for CustomNSError
We were creating domains that looked like `"main.SomeError.Type"` instead of the expected `"main.SomeError"`. Fix this and add some basic tests.
1 parent 8673a60 commit aa0cfa3

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

stdlib/public/SDK/Foundation/NSError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public protocol CustomNSError : Error {
152152
public extension CustomNSError {
153153
/// Default domain of the error.
154154
static var errorDomain: String {
155-
return String(reflecting: type(of: self))
155+
return String(reflecting: self)
156156
}
157157

158158
/// The error code within the given domain.

test/stdlib/ErrorBridged.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,11 +602,19 @@ enum DefaultCustomizedError3 : UInt, CustomNSError {
602602
}
603603
}
604604

605+
enum DefaultCustomizedParent {
606+
enum ChildError: CustomNSError {
607+
case foo
608+
}
609+
}
610+
605611
ErrorBridgingTests.test("Default-customized via CustomNSError") {
606612
expectEqual(1, (DefaultCustomizedError1.worse as NSError).code)
607613
expectEqual(13, (DefaultCustomizedError2.worse as NSError).code)
608614
expectEqual(115, (DefaultCustomizedError3.worse as NSError).code)
615+
expectEqual("main.DefaultCustomizedError1", (DefaultCustomizedError1.worse as NSError).domain)
609616
expectEqual("customized3", (DefaultCustomizedError3.worse as NSError).domain)
617+
expectEqual("main.DefaultCustomizedParent.ChildError", (DefaultCustomizedParent.ChildError.foo as NSError).domain)
610618
}
611619

612620
class MyNSError : NSError { }

0 commit comments

Comments
 (0)