Skip to content

Commit c01de63

Browse files
committed
ClangImporter: fix lookup of C++ namespaces
Sometimes when we're looking for a Swift enum, we actually want a C++ namespace.
1 parent e6a3905 commit c01de63

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2732,36 +2732,41 @@ void ClangImporter::lookupTypeDecl(
27322732
clang::DeclarationName clangName(
27332733
&Impl.Instance->getASTContext().Idents.get(rawName));
27342734

2735-
clang::Sema::LookupNameKind lookupKind;
2735+
SmallVector<clang::Sema::LookupNameKind, 1> lookupKinds;
27362736
switch (kind) {
27372737
case ClangTypeKind::Typedef:
2738-
lookupKind = clang::Sema::LookupOrdinaryName;
2738+
lookupKinds.push_back(clang::Sema::LookupOrdinaryName);
27392739
break;
27402740
case ClangTypeKind::Tag:
2741-
lookupKind = clang::Sema::LookupTagName;
2741+
lookupKinds.push_back(clang::Sema::LookupTagName);
2742+
lookupKinds.push_back(clang::Sema::LookupNamespaceName);
27422743
break;
27432744
case ClangTypeKind::ObjCProtocol:
2744-
lookupKind = clang::Sema::LookupObjCProtocolName;
2745+
lookupKinds.push_back(clang::Sema::LookupObjCProtocolName);
27452746
break;
27462747
}
27472748

27482749
// Perform name lookup into the global scope.
27492750
auto &sema = Impl.Instance->getSema();
2750-
clang::LookupResult lookupResult(sema, clangName, clang::SourceLocation(),
2751-
lookupKind);
27522751
bool foundViaClang = false;
2753-
if (!Impl.DisableSourceImport &&
2754-
sema.LookupName(lookupResult, /*Scope=*/nullptr)) {
2755-
for (auto clangDecl : lookupResult) {
2756-
if (!isa<clang::TypeDecl>(clangDecl) &&
2757-
!isa<clang::ObjCContainerDecl>(clangDecl) &&
2758-
!isa<clang::ObjCCompatibleAliasDecl>(clangDecl)) {
2759-
continue;
2760-
}
2761-
auto *imported = Impl.importDecl(clangDecl, Impl.CurrentVersion);
2762-
if (auto *importedType = dyn_cast_or_null<TypeDecl>(imported)) {
2763-
foundViaClang = true;
2764-
receiver(importedType);
2752+
2753+
for (auto lookupKind : lookupKinds) {
2754+
clang::LookupResult lookupResult(sema, clangName, clang::SourceLocation(),
2755+
lookupKind);
2756+
if (!Impl.DisableSourceImport &&
2757+
sema.LookupName(lookupResult, /*Scope=*/ sema.TUScope)) {
2758+
for (auto clangDecl : lookupResult) {
2759+
if (!isa<clang::TypeDecl>(clangDecl) &&
2760+
!isa<clang::NamespaceDecl>(clangDecl) &&
2761+
!isa<clang::ObjCContainerDecl>(clangDecl) &&
2762+
!isa<clang::ObjCCompatibleAliasDecl>(clangDecl)) {
2763+
continue;
2764+
}
2765+
auto *imported = Impl.importDecl(clangDecl, Impl.CurrentVersion);
2766+
if (auto *importedType = dyn_cast_or_null<TypeDecl>(imported)) {
2767+
foundViaClang = true;
2768+
receiver(importedType);
2769+
}
27652770
}
27662771
}
27672772
}

0 commit comments

Comments
 (0)