Skip to content

Commit f1953f3

Browse files
committed
[Macros] Don't invoke ResolveMacroRequest for the same custom attribute with
different DeclContexts.
1 parent c33c925 commit f1953f3

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

Diff for: lib/AST/Attr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2378,7 +2378,7 @@ bool CustomAttr::isArgUnsafe() const {
23782378

23792379
bool CustomAttr::isAttachedMacro(const Decl *decl) const {
23802380
auto &ctx = decl->getASTContext();
2381-
auto *dc = decl->getInnermostDeclContext();
2381+
auto *dc = decl->getDeclContext();
23822382

23832383
auto *macroDecl = evaluateOrDefault(
23842384
ctx.evaluator,

Diff for: lib/IDE/SourceEntityWalker.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ bool SemaAnnotator::handleCustomAttributes(Decl *D) {
698698
// If this attribute resolves to a macro, index that.
699699
ASTContext &ctx = D->getASTContext();
700700
ResolveMacroRequest req{const_cast<CustomAttr *>(customAttr),
701-
D->getInnermostDeclContext()};
701+
D->getDeclContext()};
702702
if (auto macroDecl = evaluateOrDefault(ctx.evaluator, req, nullptr)) {
703703
Type macroRefType = macroDecl->getDeclaredInterfaceType();
704704
if (!passReference(

Diff for: test/Serialization/Inputs/def_macros.swift

+13
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,16 @@
1111
public struct S {
1212
public var value: Int
1313
}
14+
15+
public struct Base {
16+
public static func member() -> Base { .init() }
17+
}
18+
19+
@attached(memberAttribute) public macro wrapAllProperties(
20+
_ : Base
21+
) = #externalMacro(module: "MacroDefinition", type: "WrapAllProperties")
22+
23+
@wrapAllProperties(.member())
24+
public struct TestMacroArgTypechecking {
25+
public var value: Int
26+
}

0 commit comments

Comments
 (0)