|
30 | 30 | #include "swift/Basic/STLExtras.h" |
31 | 31 | #include "swift/Basic/SourceManager.h" |
32 | 32 | #include "swift/Basic/Statistic.h" |
| 33 | +#include "swift/ClangImporter/ClangModule.h" |
33 | 34 | #include "swift/Parse/Lexer.h" |
34 | 35 | #include "llvm/ADT/DenseMap.h" |
35 | 36 | #include "llvm/ADT/TinyPtrVector.h" |
@@ -265,7 +266,8 @@ void UnqualifiedLookupFactory::performUnqualifiedLookup() { |
265 | 266 | if (!isFirstResultEnough()) { |
266 | 267 | // If no result has been found yet, the dependency must be on a top-level |
267 | 268 | // name, since up to now, the search has been for non-top-level names. |
268 | | - auto *moduleScopeContext = DC->getModuleScopeContext(); |
| 269 | + auto *moduleScopeContext = getModuleScopeLookupContext(DC); |
| 270 | + |
269 | 271 | lookUpTopLevelNamesInModuleScopeContext(moduleScopeContext); |
270 | 272 | } |
271 | 273 | } |
@@ -939,3 +941,19 @@ ValueDecl *ASTScope::lookupSingleLocalDecl(SourceFile *sf, DeclName name, |
939 | 941 | return nullptr; |
940 | 942 | return result[0]; |
941 | 943 | } |
| 944 | + |
| 945 | +DeclContext *swift::getModuleScopeLookupContext(DeclContext *dc) { |
| 946 | + auto moduleScopeContext = dc->getModuleScopeContext(); |
| 947 | + |
| 948 | + // When the module scope context is in a Clang module but we actually |
| 949 | + // have a parent source file, it's because we are within a macro |
| 950 | + // expansion triggered for the imported declaration. In such cases, |
| 951 | + // we want to use the parent source file as the lookup context, becauae |
| 952 | + // it has the appropriate resolved imports. |
| 953 | + if (isa<ClangModuleUnit>(moduleScopeContext)) { |
| 954 | + if (auto parentSF = dc->getParentSourceFile()) |
| 955 | + return parentSF; |
| 956 | + } |
| 957 | + |
| 958 | + return moduleScopeContext; |
| 959 | +} |
0 commit comments