|
30 | 30 | #include "swift/AST/ImportCache.h"
|
31 | 31 | #include "swift/AST/LinkLibrary.h"
|
32 | 32 | #include "swift/AST/Module.h"
|
| 33 | +#include "swift/AST/ModuleNameLookup.h" |
33 | 34 | #include "swift/AST/NameLookup.h"
|
34 | 35 | #include "swift/AST/NameLookupRequests.h"
|
35 | 36 | #include "swift/AST/PrettyStackTrace.h"
|
@@ -6981,9 +6982,23 @@ CustomRefCountingOperationResult CustomRefCountingOperation::evaluate(
|
6981 | 6982 | auto *clangMod = swiftDecl->getClangDecl()->getOwningModule();
|
6982 | 6983 | if (clangMod && clangMod->isSubModule())
|
6983 | 6984 | clangMod = clangMod->getTopLevelModule();
|
6984 |
| - auto parentModule = ctx.getClangModuleLoader()->getWrapperForModule(clangMod); |
6985 |
| - ctx.lookupInModule(parentModule, name, results); |
6986 |
| - |
| 6985 | + if (clangMod) { |
| 6986 | + auto parentModule = ctx.getClangModuleLoader()->getWrapperForModule(clangMod); |
| 6987 | + ctx.lookupInModule(parentModule, name, results); |
| 6988 | + } else { |
| 6989 | + // There is no Clang module for this declaration, so perform lookup from |
| 6990 | + // the main module. This will find declarations from the bridging header. |
| 6991 | + namelookup::lookupInModule( |
| 6992 | + ctx.MainModule, ctx.getIdentifier(name), results, |
| 6993 | + NLKind::UnqualifiedLookup, namelookup::ResolutionKind::Overloadable, |
| 6994 | + ctx.MainModule, SourceLoc(), NL_UnqualifiedDefault); |
| 6995 | + |
| 6996 | + // Filter out any declarations that didn't come from Clang. |
| 6997 | + auto newEnd = std::remove_if(results.begin(), results.end(), [&](ValueDecl *decl) { |
| 6998 | + return !decl->getClangDecl(); |
| 6999 | + }); |
| 7000 | + results.erase(newEnd, results.end()); |
| 7001 | + } |
6987 | 7002 | if (results.size() == 1)
|
6988 | 7003 | return {CustomRefCountingOperationResult::foundOperation, results.front(),
|
6989 | 7004 | name};
|
|
0 commit comments