Skip to content

Commit 5a6a147

Browse files
authored
Merge pull request #82691 from swiftlang/egorzhdan/cfoptions-block-param
[cxx-interop] Fix generated header for Swift closures using `CF_OPTIONS` types
2 parents eb8dcc3 + e95c9ec commit 5a6a147

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/AST/SwiftNameTranslation.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "swift/AST/SwiftNameTranslation.h"
1818
#include "swift/AST/ASTContext.h"
1919
#include "swift/AST/Attr.h"
20+
#include "swift/AST/ClangModuleLoader.h"
2021
#include "swift/AST/Decl.h"
2122
#include "swift/AST/DiagnosticsSema.h"
2223
#include "swift/AST/LazyResolver.h"
@@ -58,9 +59,15 @@ getNameForObjC(const ValueDecl *VD, CustomNamesOnly_t customNamesOnly) {
5859
if (auto clangDecl = dyn_cast_or_null<clang::NamedDecl>(VD->getClangDecl())) {
5960
if (const clang::IdentifierInfo *II = clangDecl->getIdentifier())
6061
return II->getName();
61-
if (auto *anonDecl = dyn_cast<clang::TagDecl>(clangDecl))
62+
if (auto *anonDecl = dyn_cast<clang::TagDecl>(clangDecl)) {
6263
if (auto *anonTypedef = anonDecl->getTypedefNameForAnonDecl())
6364
return anonTypedef->getIdentifier()->getName();
65+
if (auto *cfOptionsTy =
66+
VD->getASTContext()
67+
.getClangModuleLoader()
68+
->getTypeDefForCXXCFOptionsDefinition(anonDecl))
69+
return cfOptionsTy->getDecl()->getName();
70+
}
6471
}
6572

6673
return VD->getBaseIdentifier().str();

test/Interop/ObjCToSwiftToObjCxx/bridge-objc-types-back-to-objcxx.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,28 @@
3030
- (void)method;
3131
@end
3232
33+
typedef NS_OPTIONS(NSUInteger, ObjCKlassState) {
34+
ObjCKlassStateNormal = 0,
35+
};
36+
37+
//--- ObjCTest.apinotes
38+
Name: ObjCTest
39+
Tags:
40+
- Name: ObjCKlassState
41+
SwiftName: ObjCKlass.State
42+
3343
//--- module.modulemap
3444
module ObjCTest {
3545
header "header.h"
3646
}
3747

3848
//--- use-objc-types.swift
3949
import ObjCTest
50+
import Foundation
51+
52+
@objc public class HasBlockField : NSObject {
53+
@objc var foo: ((ObjCKlass.State) -> Void)?
54+
}
4055

4156
public func retObjClass() -> ObjCKlass {
4257
return ObjCKlass()
@@ -73,6 +88,10 @@ public func retObjCClassArray() -> [ObjCKlass] {
7388
return []
7489
}
7590

91+
// CHECK: @interface HasBlockField : NSObject
92+
// CHECK: @property (nonatomic, copy) void (^ _Nullable foo)(ObjCKlassState);
93+
// CHECK: @end
94+
7695
// CHECK: SWIFT_EXTERN id <ObjCProtocol> _Nonnull $s9UseObjCTy03retB9CProtocolSo0bE0_pyF(void) SWIFT_NOEXCEPT SWIFT_CALL; // retObjCProtocol()
7796
// CHECK-NEXT: #endif
7897
// CHECK-NEXT: #if defined(__OBJC__)

0 commit comments

Comments
 (0)