Skip to content

Commit 60da121

Browse files
committed
[ASTScope] Avoid adding accessors in macro expansions
`visitParsedAccessors` currently iterates over any non-implicit accessor that happens to be present. This means we end up with accessors added by macro expansions if the expansion happens before the ASTScope expansion. Make sure we avoid adding such accessors to the ASTScope tree, they should instead use their own tree. Ideally we'd better formalize `visitParsedAccessors` such that it only ever visits non-expansion accessors, but I'm leaving that for another day.
1 parent 6b502f0 commit 60da121

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/AST/ASTScopeCreation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,12 @@ ASTScopeImpl *ScopeCreator::addToScopeTreeAndReturnInsertionPoint(
610610
void ScopeCreator::addChildrenForParsedAccessors(
611611
AbstractStorageDecl *asd, ASTScopeImpl *parent) {
612612
asd->visitParsedAccessors([&](AccessorDecl *ad) {
613+
// Ignore accessors added by macro expansions.
614+
// TODO: This ought to be the default behavior of `visitParsedAccessors`,
615+
// we ought to have a different entrypoint for clients that care about
616+
// the semantic set of "explicit" accessors.
617+
if (ad->isInMacroExpansionInContext())
618+
return;
613619
assert(asd == ad->getStorage());
614620
this->addToScopeTree(ad, parent);
615621
});

0 commit comments

Comments
 (0)