ASTScope: Fix SourceFileScope source range

A SourceFile might contain TopLevelCodeDecls with guard statements,
which introduce names until the end of the file, so plumb that
through.
This commit is contained in:
Slava Pestov
2020-10-06 00:55:12 -04:00
parent dac68ca047
commit b8cccb1ef8
2 changed files with 12 additions and 14 deletions

View File

@@ -994,10 +994,8 @@ ASTSourceFileScope::expandAScopeThatCreatesANewInsertionPoint(
ScopeCreator &scopeCreator) {
ASTScopeAssert(SF, "Must already have a SourceFile.");
ArrayRef<Decl *> decls = SF->getTopLevelDecls();
// Assume that decls are only added at the end, in source order
Optional<SourceLoc> endLoc = None;
if (!decls.empty())
endLoc = decls.back()->getEndLoc();
SourceLoc endLoc = getSourceRangeOfThisASTNode().End;
std::vector<ASTNode> newNodes(decls.begin(), decls.end());
insertionPoint =