Skip to content

[4.1] [ClangImporter] Handle ns_error_domain on nameless enums with typedefs #14108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/ClangImporter/ImportEnumInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ void EnumInfo::determineConstantNamePrefix(ASTContext &ctx,
// Don't use importFullName() here, we want to ignore the swift_name
// and swift_private attributes.
StringRef enumNameStr = decl->getName();
if (enumNameStr.empty())
enumNameStr = decl->getTypedefNameForAnonDecl()->getName();
assert(!enumNameStr.empty() && "should have been classified as Constants");

StringRef commonWithEnum = getCommonPluralPrefix(checkPrefix, enumNameStr);
size_t delta = commonPrefix.size() - checkPrefix.size();

Expand Down
6 changes: 6 additions & 0 deletions test/ClangImporter/Inputs/enum-error.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ typedef NS_ERROR_ENUM(int, OtherErrorCode, OtherErrorDomain) {
OtherC,
};

extern NSString *TypedefOnlyErrorDomain;
typedef enum __attribute__((ns_error_domain(TypedefOnlyErrorDomain))) {
TypedefOnlyErrorBadness
} TypedefOnlyError;


TestError getErr();
5 changes: 5 additions & 0 deletions test/ClangImporter/enum-error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ func testDropCode(other: OtherError) -> OtherError.Code {
return other.code
}

func testImportsCorrectly() {
_ = TypedefOnlyError.badness
_ = TypedefOnlyError.Code.badness
}

func testError() {
let testErrorNSError = NSError(domain: TestErrorDomain,
code: Int(TestError.TENone.rawValue),
Expand Down