Skip to content

[cxx-interop] Import CF_OPTIONS types such as Foundation.NSTextCheckingType correctly #67301

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 14, 2023
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
3 changes: 3 additions & 0 deletions lib/ClangImporter/CFTypeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ CFPointeeInfo
CFPointeeInfo::classifyTypedef(const clang::TypedefNameDecl *typedefDecl) {
clang::QualType type = typedefDecl->getUnderlyingType();

if (auto elaborated = type->getAs<clang::ElaboratedType>())
type = elaborated->desugar();

if (auto subTypedef = type->getAs<clang::TypedefType>()) {
if (classifyTypedef(subTypedef->getDecl()))
return forTypedef(subTypedef->getDecl());
Expand Down
12 changes: 12 additions & 0 deletions test/Interop/Cxx/objc-correctness/Inputs/NSTextCheckingResult.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#define __CF_OPTIONS_ATTRIBUTES __attribute__((flag_enum,enum_extensibility(open)))
#if (__cplusplus)
#define CF_OPTIONS(_type, _name) __attribute__((availability(swift,unavailable))) _type _name; enum __CF_OPTIONS_ATTRIBUTES : _name
#else
#define CF_OPTIONS(_type, _name) enum __CF_OPTIONS_ATTRIBUTES _name : _type _name; enum _name : _type
#endif

typedef CF_OPTIONS(unsigned int, NSTextCheckingType) {
NSTextCheckingTypeOrthography = 1ULL << 0,
NSTextCheckingTypeSpelling = 1ULL << 1,
// ...
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import NSTextCheckingResult

public func foo() -> NSTextCheckingType {
return .orthography
}
5 changes: 5 additions & 0 deletions test/Interop/Cxx/objc-correctness/Inputs/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ module OSObject {
requires objc
requires cplusplus
}

module NSTextCheckingResult {
header "NSTextCheckingResult.h"
requires objc
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %S/Inputs/SwiftTextCheckingResult.swift -I %S/Inputs -module-name SwiftTextCheckingResult -enable-objc-interop -emit-module -emit-module-path %t/SwiftTextCheckingResult.swiftmodule
// RUN: %target-typecheck-verify-swift -verify-ignore-unknown -I %t -I %S/Inputs -module-name SwiftTest -enable-objc-interop -enable-experimental-cxx-interop

// REQUIRES: objc_interop

import SwiftTextCheckingResult

let _ = foo()

// CHECK: @"$sSy10FoundationE20replacingOccurrences2of4with7options5rangeSSqd___qd_0_So22NSStringCompareOptionsVSnySS5IndexVGSgtSyRd__SyRd_0_r0_lF"