Merge pull request #76456 from allevato/system-module-check

[AST] Make `IsNonUserModuleRequest` consider `SourceFile` inputs as well.
This commit is contained in:
Tony Allevato
2024-09-18 19:36:18 -04:00
committed by GitHub
5 changed files with 33 additions and 8 deletions

View File

@@ -3948,11 +3948,15 @@ bool IsNonUserModuleRequest::evaluate(Evaluator &evaluator, ModuleDecl *mod) con
if (!mod->hasName() || mod->getFiles().empty())
return false;
auto *LF = dyn_cast_or_null<LoadedFile>(mod->getFiles().front());
if (!LF)
return false;
StringRef modulePath = LF->getSourceFilename();
StringRef modulePath;
auto fileUnit = mod->getFiles().front();
if (auto *LF = dyn_cast_or_null<LoadedFile>(fileUnit)) {
modulePath = LF->getSourceFilename();
} else if (auto *SF = dyn_cast_or_null<SourceFile>(fileUnit)) {
// Checking for SourceFiles lets custom tools get the correct is-system
// state for index units when compiling a textual interface directly.
modulePath = SF->getFilename();
}
if (modulePath.empty())
return false;