Skip to content

Commit 3c40b91

Browse files
committed
[SE-0112] Strip the "Code" suffix from imported error types.
The actual code is always the nested type "Code", so it's silly to have names like "EKErrorCode.Code". Use "EKError.Code" instead.
1 parent 84dd586 commit 3c40b91

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2722,11 +2722,14 @@ auto ClangImporter::Implementation::importFullName(
27222722
baseName = baseName.substr(removePrefix.size());
27232723
strippedPrefix = true;
27242724
}
2725+
}
27252726

2726-
// If the error is an error enum, it will be mapped to the 'Code'
2727-
// enum nested within an NSError-containing struct. Strip the word
2728-
// "Code" off the end of the name, if it's there, because it's
2729-
// redundant.
2727+
// If the error is an error enum, it will be mapped to the 'Code'
2728+
// enum nested within an NSError-containing struct. Strip the word
2729+
// "Code" off the end of the name, if it's there, because it's
2730+
// redundant.
2731+
if (auto enumDecl = dyn_cast<clang::EnumDecl>(D)) {
2732+
auto enumInfo = getEnumInfo(enumDecl, &clangSema.getPreprocessor());
27302733
if (enumInfo.isErrorEnum() && baseName.size() > 4 &&
27312734
camel_case::getLastWord(baseName) == "Code")
27322735
baseName = baseName.substr(0, baseName.size() - 4);

stdlib/public/SDK/CloudKit/CloudKit.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import Foundation
33

44
@available(macOS 10.10, iOS 8.0, *)
5-
extension CKErrorCode {
5+
extension CKError {
66
/// Retrieve partial error results associated by item ID.
77
public var partialErrorsByItemID: [NSObject : Error]? {
88
return userInfo[CKPartialErrorsByItemIDKey] as? [NSObject : Error]

stdlib/public/SDK/Contacts/Contacts.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import Foundation
1515

1616
@available(macOS 10.11, iOS 9.0, *)
17-
extension CNErrorCode {
17+
extension CNError {
1818
/// One or more CNContact, CNGroup or CNContainer objects for which
1919
/// the error applies.
2020
public var affectedRecords: [AnyObject]? {

test/ClangModules/Inputs/enum-error.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,11 @@ typedef NS_ERROR_ENUM(int, TestError, TestErrorDomain) {
1212
TETwo,
1313
};
1414

15+
extern NSString *const OtherErrorDomain;
16+
typedef NS_ERROR_ENUM(int, OtherErrorCode, OtherErrorDomain) {
17+
OtherA,
18+
OtherB,
19+
OtherC,
20+
};
21+
1522
TestError getErr();

test/ClangModules/enum-error.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
import Foundation
1818

19+
func testDropCode(other: OtherError) -> OtherError.Code {
20+
return other.code
21+
}
1922

2023
func testError() {
2124
let testErrorNSError = NSError(domain: TestErrorDomain,

0 commit comments

Comments
 (0)