Skip to content

Commit b71f9d0

Browse files
authored
Merge pull request #62172 from NuriAmari/ns-option-lookup-table-warning-attempt-2
2 parents 7d108b4 + 5f5bebf commit b71f9d0

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

lib/ClangImporter/SwiftLookupTable.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,17 @@ translateDeclToContext(clang::NamedDecl *decl) {
212212
if (auto typedefDecl = tag->getTypedefNameForAnonDecl())
213213
return std::make_pair(SwiftLookupTable::ContextKind::Tag,
214214
typedefDecl->getName());
215+
if (auto enumDecl = dyn_cast<clang::EnumDecl>(tag)) {
216+
if (auto typedefType = dyn_cast<clang::TypedefType>(
217+
enumDecl->getIntegerType().getTypePtr())) {
218+
if (importer::isUnavailableInSwift(typedefType->getDecl(), nullptr,
219+
true)) {
220+
return std::make_pair(SwiftLookupTable::ContextKind::Tag,
221+
typedefType->getDecl()->getName());
222+
}
223+
}
224+
}
225+
215226
return None;
216227
}
217228

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Name: CenumsNSOptions
2+
Enumerators:
3+
- Name: API_NOTES_NAMED_OptionOne
4+
SwiftName: SwiftOptionOneApiNotes
5+
- Name: API_NOTES_NAMED_OptionTwo
6+
SwiftName: SwiftOptionTwoApiNotes
7+
- Name: API_NOTES_NAMED_OptionThree
8+
SwiftName: SwiftOptionThreeApiNotes
9+
- Name: API_NOTES_NAMED_OptionFour
10+
SwiftName: SwiftOptionFourApiNotes

test/Interop/Cxx/enum/Inputs/c-enums-NS_OPTIONS.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,22 @@ typedef NS_OPTIONS(NSUInteger, NSAttributedStringFormattingOptions) {
4040
NS_REFINED_FOR_SWIFT;
4141
@end
4242
}
43+
44+
typedef NS_OPTIONS(NSUInteger, Foo) {
45+
NS_SWIFT_NAMED_OptionOne __attribute__((swift_name("SwiftOptionOne"))) = 0,
46+
NS_SWIFT_NAMED_OptionTwo __attribute__((swift_name("SwiftOptionTwo"))) = 1
47+
<< 0,
48+
NS_SWIFT_NAMED_OptionThree
49+
__attribute__((swift_name("SwiftOptionThree"))) = 1 << 1,
50+
NS_SWIFT_NAMED_OptionFour
51+
__attribute__((swift_name("SwiftOptionFour"))) = NS_SWIFT_NAMED_OptionOne |
52+
NS_SWIFT_NAMED_OptionTwo
53+
};
54+
55+
typedef NS_OPTIONS(NSUInteger, Bar) {
56+
API_NOTES_NAMED_OptionOne = 0,
57+
API_NOTES_NAMED_OptionTwo = 1 << 0,
58+
API_NOTES_NAMED_OptionThree = 1 << 1,
59+
API_NOTES_NAMED_OptionFour = API_NOTES_NAMED_OptionOne |
60+
API_NOTES_NAMED_OptionTwo
61+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %empty-directory(%t/cache)
2+
// RUN: %target-swift-frontend %s -I %S/Inputs -typecheck -module-cache-path %t/cache -enable-experimental-cxx-interop 2>&1 | %FileCheck --allow-empty %s
3+
4+
// REQUIRES: objc_interop
5+
6+
import CenumsNSOptions
7+
8+
// CHECK-NOT: warning: imported declaration 'API_NOTES_NAMED_OptionOne' could not be mapped to 'SwiftOptionOneApiNotes'
9+
// CHECK-NOT: warning: imported declaration 'API_NOTES_NAMED_OptionTwo' could not be mapped to 'SwiftOptionTwoApiNotes'
10+
// CHECK-NOT: warning: imported declaration 'API_NOTES_NAMED_OptionThree' could not be mapped to 'SwiftOptionThreeApiNotes'
11+
// CHECK-NOT: warning: imported declaration 'API_NOTES_NAMED_OptionFour' could not be mapped to 'SwiftOptionFourApiNotes'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %empty-directory(%t/cache)
2+
// RUN: %target-swift-frontend %s -I %S/Inputs -typecheck -module-cache-path %t/cache -enable-experimental-cxx-interop 2>&1 | %FileCheck --allow-empty %s
3+
4+
// REQUIRES: objc_interop
5+
6+
import CenumsNSOptions
7+
8+
// CHECK-NOT: warning: imported declaration 'NS_SWIFT_NAMED_OptionOne' could not be mapped to 'SwiftOptionOne'
9+
// CHECK-NOT: warning: imported declaration 'NS_SWIFT_NAMED_OptionTwo' could not be mapped to 'SwiftOptionTwo'
10+
// CHECK-NOT: warning: imported declaration 'NS_SWIFT_NAMED_OptionThree' could not be mapped to 'SwiftOptionThree'
11+
// CHECK-NOT: warning: imported declaration 'NS_SWIFT_NAMED_OptionFour' could not be mapped to 'SwiftOptionFour'

0 commit comments

Comments
 (0)