Skip to content

Commit 9ba33cd

Browse files
authored
Merge pull request #67096 from plotfi/ns-options-type-import-inside-objc-interface-2
[cxx-interop] Add-on commits to previous NS_OPTIONS fix PR
2 parents 498ce63 + 9369908 commit 9ba33cd

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
@@ -816,8 +816,8 @@ static bool isPrintLikeMethod(DeclName name, const DeclContext *dc) {
816816
using MirroredMethodEntry =
817817
std::tuple<const clang::ObjCMethodDecl*, ProtocolDecl*, bool /*isAsync*/>;
818818

819-
ImportedType tryImportOptionsTypeForField(const clang::QualType type,
820-
ClangImporter::Implementation &Impl) {
819+
ImportedType findOptionSetType(clang::QualType type,
820+
ClangImporter::Implementation &Impl) {
821821
ImportedType importedType;
822822
auto fieldType = type;
823823
if (auto elaborated = dyn_cast<clang::ElaboratedType>(fieldType))
@@ -3689,7 +3689,7 @@ namespace {
36893689
}
36903690

36913691
auto fieldType = decl->getType();
3692-
ImportedType importedType = tryImportOptionsTypeForField(fieldType, Impl);
3692+
ImportedType importedType = findOptionSetType(fieldType, Impl);
36933693

36943694
if (!importedType)
36953695
importedType =
@@ -5212,7 +5212,7 @@ namespace {
52125212
}
52135213

52145214
auto fieldType = decl->getType();
5215-
ImportedType importedType = tryImportOptionsTypeForField(fieldType, Impl);
5215+
ImportedType importedType = findOptionSetType(fieldType, Impl);
52165216

52175217
if (!importedType)
52185218
importedType = Impl.importPropertyType(decl, isInSystemModule(dc));

lib/ClangImporter/ImportType.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3224,8 +3224,8 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
32243224
importedType.isImplicitlyUnwrapped()};
32253225
}
32263226

3227-
ImportedType tryImportOptionsTypeForField(const clang::QualType type,
3228-
ClangImporter::Implementation &Impl);
3227+
ImportedType findOptionSetType(clang::QualType type,
3228+
ClangImporter::Implementation &Impl);
32293229

32303230
ImportedType ClangImporter::Implementation::importAccessorParamsAndReturnType(
32313231
const DeclContext *dc, const clang::ObjCPropertyDecl *property,
@@ -3250,13 +3250,13 @@ ImportedType ClangImporter::Implementation::importAccessorParamsAndReturnType(
32503250
DeclContext *origDC = importDeclContextOf(property,
32513251
property->getDeclContext());
32523252
assert(origDC);
3253-
auto fieldType = isGetter ? clangDecl->getReturnType() : clangDecl->getParamDecl(0)->getType();
3254-
ImportedType importedNSOptionsType = tryImportOptionsTypeForField(fieldType, *this);
3253+
auto fieldType = isGetter ? clangDecl->getReturnType()
3254+
: clangDecl->getParamDecl(0)->getType();
32553255

32563256
// Import the property type, independent of what kind of accessor this is.
3257-
auto importedType = importPropertyType(property, isFromSystemModule);
3258-
if (importedNSOptionsType)
3259-
importedType = importedNSOptionsType;
3257+
ImportedType importedType = findOptionSetType(fieldType, *this);
3258+
if (!importedType)
3259+
importedType = importPropertyType(property, isFromSystemModule);
32603260
if (!importedType)
32613261
return {Type(), false};
32623262

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)