Skip to content

Commit 5db8647

Browse files
committed
[cxx-interop] Make sure to use TUScope when looking up clang decls.
When we look up a name directly, make sure we provide a scope, this is required when C++ interop is enabled. This issue was exposed when we look up if an NSString is hashable. There is a special case for classes that inherit from NSObject, but we didn't see that, because we couldn't find NSObject (because lookup failed).
1 parent 7390f7d commit 5db8647

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
@@ -3071,7 +3071,7 @@ Decl *ClangImporter::Implementation::importDeclByName(StringRef name) {
30713071
clang::LookupResult lookupResult(sema, clangName, clang::SourceLocation(),
30723072
clang::Sema::LookupOrdinaryName);
30733073
lookupResult.setAllowHidden(true);
3074-
if (!sema.LookupName(lookupResult, /*Scope=*/nullptr)) {
3074+
if (!sema.LookupName(lookupResult, /*Scope=*/sema.TUScope)) {
30753075
return nullptr;
30763076
}
30773077

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef TEST_INTEROP_CXX_CLASS_INPUTS_DESTRUCTORS_H
2+
#define TEST_INTEROP_CXX_CLASS_INPUTS_DESTRUCTORS_H
3+
4+
#import <Foundation/Foundation.h>
5+
6+
void takesDictionaryOfStrings(NSDictionary<NSString*, NSString*>*_Nonnull a) { }
7+
8+
#endif // TEST_INTEROP_CXX_CLASS_INPUTS_DESTRUCTORS_H

test/Interop/Cxx/class/Inputs/module.modulemap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,8 @@ module ClassProtocolNameClash {
9292
header "class-protocol-name-clash.h"
9393
requires cplusplus
9494
}
95+
96+
module DictionaryOfNSStrings {
97+
header "dictionary-of-nsstrings.h"
98+
requires cplusplus
99+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %target-swift-ide-test -print-module -module-to-print=DictionaryOfNSStrings -I %S/Inputs/ -source-filename=x -enable-cxx-interop | %FileCheck %s
2+
3+
// REQUIRES: objc_interop
4+
5+
// CHECK: func takesDictionaryOfStrings(_ a: [String : String])

0 commit comments

Comments
 (0)