Skip to content

Commit 40c4f3c

Browse files
authored
Merge pull request #82723 from swiftlang/egorzhdan/6.2-cfoptions-block-param
🍒[cxx-interop] Fix generated header for Swift closures using `CF_OPTIONS` types
2 parents 075fc7d + 0be39ef commit 40c4f3c

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
@@ -16,6 +16,7 @@
1616

1717
#include "swift/AST/SwiftNameTranslation.h"
1818
#include "swift/AST/ASTContext.h"
19+
#include "swift/AST/ClangModuleLoader.h"
1920
#include "swift/AST/Decl.h"
2021
#include "swift/AST/DiagnosticsSema.h"
2122
#include "swift/AST/LazyResolver.h"
@@ -54,9 +55,15 @@ getNameForObjC(const ValueDecl *VD, CustomNamesOnly_t customNamesOnly) {
5455
if (auto clangDecl = dyn_cast_or_null<clang::NamedDecl>(VD->getClangDecl())) {
5556
if (const clang::IdentifierInfo *II = clangDecl->getIdentifier())
5657
return II->getName();
57-
if (auto *anonDecl = dyn_cast<clang::TagDecl>(clangDecl))
58+
if (auto *anonDecl = dyn_cast<clang::TagDecl>(clangDecl)) {
5859
if (auto *anonTypedef = anonDecl->getTypedefNameForAnonDecl())
5960
return anonTypedef->getIdentifier()->getName();
61+
if (auto *cfOptionsTy =
62+
VD->getASTContext()
63+
.getClangModuleLoader()
64+
->getTypeDefForCXXCFOptionsDefinition(anonDecl))
65+
return cfOptionsTy->getDecl()->getName();
66+
}
6067
}
6168

6269
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)