Skip to content

Commit 1338edd

Browse files
committed
[cxx-interop] Import ObjCPropertyDecl of type NS_OPTIONS fields a struct type
Try importing ObjCPropertyDecl field types the C++-Interop-NS_OPTIONS way. This will fix cases such as: ``` import UIKit func f(gesture: UISwipeGestureRecognizer, direction: UISwipeGestureRecognizer.Direction) { gesture.direction = direction // error } ``` because it will make sure the field inside class UIGestureRecognizer is of the enum-struct type and not the typedef-rawValue type when importing an ObjC class.
1 parent ec5b7b0 commit 1338edd

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5211,7 +5211,11 @@ namespace {
52115211
}
52125212
}
52135213

5214-
auto importedType = Impl.importPropertyType(decl, isInSystemModule(dc));
5214+
auto fieldType = decl->getType();
5215+
ImportedType importedType = tryImportOptionsTypeForField(fieldType, Impl);
5216+
5217+
if (!importedType)
5218+
importedType = Impl.importPropertyType(decl, isInSystemModule(dc));
52155219
if (!importedType) {
52165220
Impl.addImportDiagnostic(
52175221
decl, Diagnostic(diag::objc_property_not_imported, decl),

lib/ClangImporter/ImportType.cpp

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

3227+
ImportedType tryImportOptionsTypeForField(const clang::QualType type,
3228+
ClangImporter::Implementation &Impl);
3229+
32273230
ImportedType ClangImporter::Implementation::importAccessorParamsAndReturnType(
32283231
const DeclContext *dc, const clang::ObjCPropertyDecl *property,
32293232
const clang::ObjCMethodDecl *clangDecl, bool isFromSystemModule,
@@ -3247,9 +3250,13 @@ ImportedType ClangImporter::Implementation::importAccessorParamsAndReturnType(
32473250
DeclContext *origDC = importDeclContextOf(property,
32483251
property->getDeclContext());
32493252
assert(origDC);
3253+
auto fieldType = isGetter ? clangDecl->getReturnType() : clangDecl->getParamDecl(0)->getType();
3254+
ImportedType importedNSOptionsType = tryImportOptionsTypeForField(fieldType, *this);
32503255

32513256
// Import the property type, independent of what kind of accessor this is.
32523257
auto importedType = importPropertyType(property, isFromSystemModule);
3258+
if (importedNSOptionsType)
3259+
importedType = importedNSOptionsType;
32533260
if (!importedType)
32543261
return {Type(), false};
32553262

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ struct HasNSOptionField {
8282
Bar bar;
8383
};
8484

85+
@interface HasNSOptionFieldObjC
86+
@property Bar bar;
87+
@end
88+
8589
Baz CFunctionReturningNSOption();
8690
void CFunctionTakingNSOption(Baz);
8791

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ import CenumsNSOptions
2525
// CHECK: struct HasNSOptionField {
2626
// CHECK: var bar: Bar
2727
// CHECK: }
28+
29+
// CHECK: class HasNSOptionFieldObjC {
30+
// CHECK: var bar: Bar
31+
// CHECK: }

0 commit comments

Comments
 (0)