Skip to content
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
11 changes: 11 additions & 0 deletions lib/ClangImporter/SwiftLookupTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,17 @@ translateDeclToContext(clang::NamedDecl *decl) {
if (auto typedefDecl = tag->getTypedefNameForAnonDecl())
return std::make_pair(SwiftLookupTable::ContextKind::Tag,
typedefDecl->getName());
if (auto enumDecl = dyn_cast<clang::EnumDecl>(tag)) {
if (auto typedefType = dyn_cast<clang::TypedefType>(
enumDecl->getIntegerType().getTypePtr())) {
if (importer::isUnavailableInSwift(typedefType->getDecl(), nullptr,
true)) {
return std::make_pair(SwiftLookupTable::ContextKind::Tag,
typedefType->getDecl()->getName());
}
}
}

return None;
}

Expand Down
10 changes: 10 additions & 0 deletions test/Interop/Cxx/enum/Inputs/CenumsNSOptions.apinotes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Name: CenumsNSOptions
Enumerators:
- Name: API_NOTES_NAMED_OptionOne
SwiftName: SwiftOptionOneApiNotes
- Name: API_NOTES_NAMED_OptionTwo
SwiftName: SwiftOptionTwoApiNotes
- Name: API_NOTES_NAMED_OptionThree
SwiftName: SwiftOptionThreeApiNotes
- Name: API_NOTES_NAMED_OptionFour
SwiftName: SwiftOptionFourApiNotes
19 changes: 19 additions & 0 deletions test/Interop/Cxx/enum/Inputs/c-enums-NS_OPTIONS.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,22 @@ typedef NS_OPTIONS(NSUInteger, NSAttributedStringFormattingOptions) {
NS_REFINED_FOR_SWIFT;
@end
}

typedef NS_OPTIONS(NSUInteger, Foo) {
NS_SWIFT_NAMED_OptionOne __attribute__((swift_name("SwiftOptionOne"))) = 0,
NS_SWIFT_NAMED_OptionTwo __attribute__((swift_name("SwiftOptionTwo"))) = 1
<< 0,
NS_SWIFT_NAMED_OptionThree
__attribute__((swift_name("SwiftOptionThree"))) = 1 << 1,
NS_SWIFT_NAMED_OptionFour
__attribute__((swift_name("SwiftOptionFour"))) = NS_SWIFT_NAMED_OptionOne |
NS_SWIFT_NAMED_OptionTwo
};

typedef NS_OPTIONS(NSUInteger, Bar) {
API_NOTES_NAMED_OptionOne = 0,
API_NOTES_NAMED_OptionTwo = 1 << 0,
API_NOTES_NAMED_OptionThree = 1 << 1,
API_NOTES_NAMED_OptionFour = API_NOTES_NAMED_OptionOne |
API_NOTES_NAMED_OptionTwo
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: %empty-directory(%t/cache)
Copy link
Contributor Author

@NuriAmari NuriAmari Nov 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hyp I think @drodriguez found the issue, these two tests were sharing a module cache and emptying it at the start of the test. If these tests are run concurrently you get weird flaky failures. I've changed %T -> %t to make sure the module cache directories are distinct.

// RUN: %target-swift-frontend %s -I %S/Inputs -typecheck -module-cache-path %t/cache -enable-experimental-cxx-interop 2>&1 | %FileCheck --allow-empty %s

// REQUIRES: objc_interop

import CenumsNSOptions

// CHECK-NOT: warning: imported declaration 'API_NOTES_NAMED_OptionOne' could not be mapped to 'SwiftOptionOneApiNotes'
// CHECK-NOT: warning: imported declaration 'API_NOTES_NAMED_OptionTwo' could not be mapped to 'SwiftOptionTwoApiNotes'
// CHECK-NOT: warning: imported declaration 'API_NOTES_NAMED_OptionThree' could not be mapped to 'SwiftOptionThreeApiNotes'
// CHECK-NOT: warning: imported declaration 'API_NOTES_NAMED_OptionFour' could not be mapped to 'SwiftOptionFourApiNotes'
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: %empty-directory(%t/cache)
// RUN: %target-swift-frontend %s -I %S/Inputs -typecheck -module-cache-path %t/cache -enable-experimental-cxx-interop 2>&1 | %FileCheck --allow-empty %s

// REQUIRES: objc_interop

import CenumsNSOptions

// CHECK-NOT: warning: imported declaration 'NS_SWIFT_NAMED_OptionOne' could not be mapped to 'SwiftOptionOne'
// CHECK-NOT: warning: imported declaration 'NS_SWIFT_NAMED_OptionTwo' could not be mapped to 'SwiftOptionTwo'
// CHECK-NOT: warning: imported declaration 'NS_SWIFT_NAMED_OptionThree' could not be mapped to 'SwiftOptionThree'
// CHECK-NOT: warning: imported declaration 'NS_SWIFT_NAMED_OptionFour' could not be mapped to 'SwiftOptionFour'