Skip to content

Commit 138304a

Browse files
committed
[ClangImporter] Handle ns_error_domain on nameless enums with typedefs
This doesn't come up when using the NS_ERROR_ENUM macro, but it shouldn't crash the compiler, and it was easy enough to fix.
1 parent 63d98e6 commit 138304a

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

lib/ClangImporter/ImportEnumInfo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ void EnumInfo::determineConstantNamePrefix(ASTContext &ctx,
308308
// Don't use importFullName() here, we want to ignore the swift_name
309309
// and swift_private attributes.
310310
StringRef enumNameStr = decl->getName();
311+
if (enumNameStr.empty())
312+
enumNameStr = decl->getTypedefNameForAnonDecl()->getName();
313+
assert(!enumNameStr.empty() && "should have been classified as Constants");
314+
311315
StringRef commonWithEnum = getCommonPluralPrefix(checkPrefix, enumNameStr);
312316
size_t delta = commonPrefix.size() - checkPrefix.size();
313317

test/ClangImporter/Inputs/enum-error.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@ typedef NS_ERROR_ENUM(int, OtherErrorCode, OtherErrorDomain) {
1919
OtherC,
2020
};
2121

22+
extern NSString *TypedefOnlyErrorDomain;
23+
typedef enum __attribute__((ns_error_domain(TypedefOnlyErrorDomain))) {
24+
TypedefOnlyErrorBadness
25+
} TypedefOnlyError;
26+
27+
2228
TestError getErr();

test/ClangImporter/enum-error.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ func testDropCode(other: OtherError) -> OtherError.Code {
2121
return other.code
2222
}
2323

24+
func testImportsCorrectly() {
25+
_ = TypedefOnlyError.badness
26+
_ = TypedefOnlyError.Code.badness
27+
}
28+
2429
func testError() {
2530
let testErrorNSError = NSError(domain: TestErrorDomain,
2631
code: Int(TestError.TENone.rawValue),

0 commit comments

Comments
 (0)