Skip to content

Commit 1adb611

Browse files
committed
[cxx-interop] Add anonymous enum logic to importFunctionReturnType().
1 parent c6cea1e commit 1adb611

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,6 +2091,20 @@ ImportedType ClangImporter::Implementation::importFunctionReturnType(
20912091
->isTemplateTypeParmType())
20922092
OptionalityOfReturn = OTK_None;
20932093

2094+
if (auto typedefType = dyn_cast<clang::TypedefType>(clangDecl->getReturnType().getTypePtr())) {
2095+
if (isUnavailableInSwift(typedefType->getDecl())) {
2096+
if (auto clangEnum = findAnonymousEnumForTypedef(SwiftContext, typedefType)) {
2097+
// If this fails, it means that we need a stronger predicate for
2098+
// determining the relationship between an enum and typedef.
2099+
assert(clangEnum.getValue()->getIntegerType()->getCanonicalTypeInternal() ==
2100+
typedefType->getCanonicalTypeInternal());
2101+
if (auto swiftEnum = importDecl(*clangEnum, CurrentVersion)) {
2102+
return {cast<NominalTypeDecl>(swiftEnum)->getDeclaredType(), false};
2103+
}
2104+
}
2105+
}
2106+
}
2107+
20942108
// Import the result type.
20952109
return importType(clangDecl->getReturnType(),
20962110
(isAuditedResult ? ImportTypeKind::AuditedResult

test/Interop/Cxx/enum/Inputs/anonymous-with-swift-name.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ inline CFColorMask useCFColorMask(CFColorMask mask) { return mask; }
2424

2525
struct ParentStruct { };
2626

27+
inline CFColorMask renameCFColorMask(ParentStruct parent)
28+
__attribute__((swift_name("ParentStruct.childFn(self:)")))
29+
{ return kSOColorMaskRed; }
30+
2731
typedef __attribute__((availability(swift, unavailable))) __attribute__((swift_name("ParentStruct.NewName"))) unsigned OldName;
2832

2933
enum __attribute__((flag_enum,enum_extensibility(open))) : OldName {

test/Interop/Cxx/enum/anonymous-with-swift-name-module-interface.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@
6060
// Test rename with "swift_name" attr:
6161
// CHECK: struct ParentStruct
6262

63-
// CHECK: @available(swift, obsoleted: 3, renamed: "ParentStruct.NewName")
64-
// CHECK: @available(*, unavailable, message: "Not available in Swift")
65-
// CHECK: typealias OldName = ParentStruct.NewName
63+
// CHECK: @available(swift, obsoleted: 3, renamed: "ParentStruct.childFn(self:)")
64+
// CHECK: func renameCFColorMask(_ parent: ParentStruct) -> CFColorMask
65+
6666
// CHECK: extension ParentStruct {
67+
// CHECK: func childFn() -> CFColorMask
6768
// CHECK: @available(*, unavailable, message: "Not available in Swift")
6869
// CHECK: typealias NewName = UInt32
6970
// CHECK: struct NewName : OptionSet, @unchecked Sendable {
@@ -81,6 +82,10 @@
8182
// CHECK: }
8283
// CHECK: }
8384

85+
// CHECK: @available(swift, obsoleted: 3, renamed: "ParentStruct.NewName")
86+
// CHECK: @available(*, unavailable, message: "Not available in Swift")
87+
// CHECK: typealias OldName = ParentStruct.NewName
88+
8489
// CHECK: @available(swift, obsoleted: 3, renamed: "ParentStruct.NewName")
8590
// CHECK: typealias OldName = ParentStruct.NewName
8691
// CHECK: @available(*, unavailable, message: "Not available in Swift")

0 commit comments

Comments
 (0)