Skip to content

Commit e008eba

Browse files
committed
[cxx-interop] Import OS_OBJECT_DECL consistently with and without C++ interop enabled
Previously ClangImporter was not able to lookup `NSObject` when C++ interop is enabled, which caused types such as `xpc_object_t` from system module XPC to be imported differently: `any OS_xpc_object` without C++ interop vs `any NSObject & OS_xpc_object` with C++ interop enabled. rdar://110000787 (cherry picked from commit 5a62032)
1 parent 6f1cf76 commit e008eba

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3418,7 +3418,7 @@ static Type getNamedProtocolType(ClangImporter::Implementation &impl,
34183418
clang::LookupResult lookupResult(sema, clangName, clang::SourceLocation(),
34193419
clang::Sema::LookupObjCProtocolName);
34203420
lookupResult.setAllowHidden(true);
3421-
if (!sema.LookupName(lookupResult, /*Scope=*/nullptr))
3421+
if (!sema.LookupName(lookupResult, /*Scope=*/sema.TUScope))
34223422
return Type();
34233423

34243424
for (auto decl : lookupResult) {

test/Interop/Cxx/objc-correctness/Inputs/module.modulemap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ module NSNofiticationBridging {
1818
requires objc
1919
requires cplusplus
2020
}
21+
22+
module OSObject {
23+
header "os-object.h"
24+
requires objc
25+
requires cplusplus
26+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include <os/object.h>
2+
3+
/// Similar to xpc_object_t
4+
OS_OBJECT_DECL(my_object);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %target-swift-frontend -typecheck -verify -I %S/Inputs -cxx-interoperability-mode=swift-5.9 %s
2+
// REQUIRES: objc_interop
3+
4+
import OSObject
5+
6+
extension my_object_t {
7+
func dummy() {}
8+
}

0 commit comments

Comments
 (0)