[SourceKit] Fix placeholder expansion not working inside #if

Update the PlaceholderFinder ASTWalker to walk into the clauses of
IfConfigDecls. It wasn't previously, resulting in any placeholders there not
being expanded.

Also update CallExprFinder (used to determine if expansions should use trailing
closure syntax) to walk into inactive if-config clauses. Previously it only
walked into active regions, so expansions never used trailing closure syntax in
inactive regions.

Resolves rdar://problem/51995648
This commit is contained in:
Nathan Hawes
2019-07-09 13:40:48 -07:00
parent 35c0fa86b4
commit 0d59bffd81
2 changed files with 39 additions and 0 deletions

View File

@@ -1409,6 +1409,22 @@ private:
}
return { true, E };
}
bool walkToDeclPre(Decl *D) override {
if (auto *ICD = dyn_cast<IfConfigDecl>(D)) {
// The base walker assumes the content of active IfConfigDecl clauses
// has been injected into the parent context and will be walked there.
// This doesn't hold for pre-typechecked ASTs and we need to find
// placeholders in inactive clauses anyway, so walk them here.
for (auto Clause: ICD->getClauses()) {
for (auto Elem: Clause.Elements) {
Elem.walk(*this);
}
}
return false;
}
return true;
}
};
class ClosureTypeWalker: public ASTWalker {
@@ -1571,6 +1587,8 @@ private:
return true;
}
bool shouldWalkInactiveConfigRegion() override { return true; }
Expr *findEnclosingCallArg(SourceFile &SF, SourceLoc SL) {
EnclosingCallAndArg = {nullptr, nullptr};
OuterExpr = nullptr;