Skip to content

Commit 09a56a8

Browse files
committed
[cxx-interop] Add-on commits to previous NS_OPTIONS fix PR
Add-on to address comments from #67036 Addresses some nits, test addons, and some code cleanups/improvement. (cherry picked from commit 9369908)
1 parent c4e0586 commit 09a56a8

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -818,8 +818,8 @@ static bool isPrintLikeMethod(DeclName name, const DeclContext *dc) {
818818
using MirroredMethodEntry =
819819
std::tuple<const clang::ObjCMethodDecl*, ProtocolDecl*, bool /*isAsync*/>;
820820

821-
ImportedType tryImportOptionsTypeForField(const clang::QualType type,
822-
ClangImporter::Implementation &Impl) {
821+
ImportedType findOptionSetType(clang::QualType type,
822+
ClangImporter::Implementation &Impl) {
823823
ImportedType importedType;
824824
auto fieldType = type;
825825
if (auto elaborated = dyn_cast<clang::ElaboratedType>(fieldType))
@@ -3676,7 +3676,7 @@ namespace {
36763676
}
36773677

36783678
auto fieldType = decl->getType();
3679-
ImportedType importedType = tryImportOptionsTypeForField(fieldType, Impl);
3679+
ImportedType importedType = findOptionSetType(fieldType, Impl);
36803680

36813681
if (!importedType)
36823682
importedType =
@@ -5202,7 +5202,7 @@ namespace {
52025202
}
52035203

52045204
auto fieldType = decl->getType();
5205-
ImportedType importedType = tryImportOptionsTypeForField(fieldType, Impl);
5205+
ImportedType importedType = findOptionSetType(fieldType, Impl);
52065206

52075207
if (!importedType)
52085208
importedType = Impl.importPropertyType(decl, isInSystemModule(dc));

lib/ClangImporter/ImportType.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3212,8 +3212,8 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
32123212
importedType.isImplicitlyUnwrapped()};
32133213
}
32143214

3215-
ImportedType tryImportOptionsTypeForField(const clang::QualType type,
3216-
ClangImporter::Implementation &Impl);
3215+
ImportedType findOptionSetType(clang::QualType type,
3216+
ClangImporter::Implementation &Impl);
32173217

32183218
ImportedType ClangImporter::Implementation::importAccessorParamsAndReturnType(
32193219
const DeclContext *dc, const clang::ObjCPropertyDecl *property,
@@ -3238,13 +3238,13 @@ ImportedType ClangImporter::Implementation::importAccessorParamsAndReturnType(
32383238
DeclContext *origDC = importDeclContextOf(property,
32393239
property->getDeclContext());
32403240
assert(origDC);
3241-
auto fieldType = isGetter ? clangDecl->getReturnType() : clangDecl->getParamDecl(0)->getType();
3242-
ImportedType importedNSOptionsType = tryImportOptionsTypeForField(fieldType, *this);
3241+
auto fieldType = isGetter ? clangDecl->getReturnType()
3242+
: clangDecl->getParamDecl(0)->getType();
32433243

32443244
// Import the property type, independent of what kind of accessor this is.
3245-
auto importedType = importPropertyType(property, isFromSystemModule);
3246-
if (importedNSOptionsType)
3247-
importedType = importedNSOptionsType;
3245+
ImportedType importedType = findOptionSetType(fieldType, *this);
3246+
if (!importedType)
3247+
importedType = importPropertyType(property, isFromSystemModule);
32483248
if (!importedType)
32493249
return {Type(), false};
32503250

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ struct HasNSOptionField {
8686
@property Bar bar;
8787
@end
8888

89+
@interface HasNSOptionFieldObjC2
90+
- (void)setBar:(Bar)bar;
91+
@end
92+
8993
Baz CFunctionReturningNSOption();
9094
void CFunctionTakingNSOption(Baz);
9195

test/Interop/Cxx/enum/c-enums-NS_OPTIONS.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,8 @@ import CenumsNSOptions
3131
// CHECK-NEXT: class func bar() -> Bar
3232
// CHECK-NEXT: class func setBar(_ bar: Bar)
3333
// CHECK-NEXT: }
34+
35+
// CHECK: class HasNSOptionFieldObjC2 {
36+
// CHECK-NEXT: class func setBar(_ bar: Bar)
37+
// CHECK-NEXT: func setBar(_ bar: Bar)
38+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)