Skip to content

[cxx-interop] Fix generated header for Swift closures using CF_OPTIONS types #82691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/AST/SwiftNameTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "swift/AST/SwiftNameTranslation.h"
#include "swift/AST/ASTContext.h"
#include "swift/AST/Attr.h"
#include "swift/AST/ClangModuleLoader.h"
#include "swift/AST/Decl.h"
#include "swift/AST/DiagnosticsSema.h"
#include "swift/AST/LazyResolver.h"
Expand Down Expand Up @@ -58,9 +59,15 @@ getNameForObjC(const ValueDecl *VD, CustomNamesOnly_t customNamesOnly) {
if (auto clangDecl = dyn_cast_or_null<clang::NamedDecl>(VD->getClangDecl())) {
if (const clang::IdentifierInfo *II = clangDecl->getIdentifier())
return II->getName();
if (auto *anonDecl = dyn_cast<clang::TagDecl>(clangDecl))
if (auto *anonDecl = dyn_cast<clang::TagDecl>(clangDecl)) {
if (auto *anonTypedef = anonDecl->getTypedefNameForAnonDecl())
return anonTypedef->getIdentifier()->getName();
if (auto *cfOptionsTy =
VD->getASTContext()
.getClangModuleLoader()
->getTypeDefForCXXCFOptionsDefinition(anonDecl))
return cfOptionsTy->getDecl()->getName();
}
}

return VD->getBaseIdentifier().str();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,28 @@
- (void)method;
@end

typedef NS_OPTIONS(NSUInteger, ObjCKlassState) {
ObjCKlassStateNormal = 0,
};

//--- ObjCTest.apinotes
Name: ObjCTest
Tags:
- Name: ObjCKlassState
SwiftName: ObjCKlass.State

//--- module.modulemap
module ObjCTest {
header "header.h"
}

//--- use-objc-types.swift
import ObjCTest
import Foundation

@objc public class HasBlockField : NSObject {
@objc var foo: ((ObjCKlass.State) -> Void)?
}

public func retObjClass() -> ObjCKlass {
return ObjCKlass()
Expand Down Expand Up @@ -73,6 +88,10 @@ public func retObjCClassArray() -> [ObjCKlass] {
return []
}

// CHECK: @interface HasBlockField : NSObject
// CHECK: @property (nonatomic, copy) void (^ _Nullable foo)(ObjCKlassState);
// CHECK: @end

// CHECK: SWIFT_EXTERN id <ObjCProtocol> _Nonnull $s9UseObjCTy03retB9CProtocolSo0bE0_pyF(void) SWIFT_NOEXCEPT SWIFT_CALL; // retObjCProtocol()
// CHECK-NEXT: #endif
// CHECK-NEXT: #if defined(__OBJC__)
Expand Down