Skip to content

Commit 6b502f0

Browse files
committed
[AST] Handle accessors specially in isInMacroExpansionInContext
Rather than looking at their DeclContext, look at the location of their storage. This allows us to differentiate accessors added by macro expansions vs accessors that are attached to storage that's in a macro expansion.
1 parent 62839d1 commit 6b502f0

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/AST/Decl.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,11 +1007,21 @@ SourceRange Decl::getSourceRangeIncludingAttrs() const {
10071007
}
10081008

10091009
bool Decl::isInMacroExpansionInContext() const {
1010-
auto *dc = getDeclContext();
1011-
auto parentFile = dc->getParentSourceFile();
10121010
auto *mod = getModuleContext();
10131011
auto *file = mod->getSourceFileContainingLocation(getStartLoc());
10141012

1013+
auto parentFile = [&]() {
1014+
// For accessors, the storage decl is the more accurate thing to check
1015+
// since the entire property/subscript could be macro-generated, in which
1016+
// case the accessor shouldn't be considered "added by macro expansion".
1017+
if (auto *accessor = dyn_cast<AccessorDecl>(this)) {
1018+
auto storageLoc = accessor->getStorage()->getLoc();
1019+
if (storageLoc.isValid())
1020+
return mod->getSourceFileContainingLocation(storageLoc);
1021+
}
1022+
return getDeclContext()->getParentSourceFile();
1023+
}();
1024+
10151025
// Decls in macro expansions always have a source file. The source
10161026
// file can be null if the decl is implicit or has an invalid
10171027
// source location.

0 commit comments

Comments
 (0)