Skip to content

Commit bf5aad6

Browse files
committed
[Macros] Fix duplicate diagnostics for macro attributes.
Type wrappers were invoking CustomAttrDeclRequest with a decl context of the attached nominal type rather than its decl context, so the request was invoked twice for the same custom attributes with different decl contexts.
1 parent 94abc25 commit bf5aad6

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

lib/Sema/TypeCheckTypeWrapper.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ static void getTypeWrappers(NominalTypeDecl *decl,
124124
for (auto *attr : decl->getAttrs().getAttributes<CustomAttr>()) {
125125
auto *mutableAttr = const_cast<CustomAttr *>(attr);
126126
auto found = evaluateOrDefault(
127-
ctx.evaluator, CustomAttrDeclRequest{mutableAttr, decl}, nullptr);
127+
ctx.evaluator,
128+
CustomAttrDeclRequest{mutableAttr, decl->getDeclContext()},
129+
nullptr);
128130

129131
if (!found)
130132
continue;

test/Macros/attached_macros_diags.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66

77
@attached(accessor) macro m2(_: Int) -> Void = #externalMacro(module: "MyMacros", type: "Macro2")
88
// expected-warning@-1{{external macro implementation type 'MyMacros.Macro2' could not be found for macro 'm2'}}
9-
// expected-note@-2 2{{candidate has partially matching parameter list (Int)}}
9+
// expected-note@-2{{candidate has partially matching parameter list (Int)}}
1010

1111
@attached(accessor) macro m2(_: Double) -> Void = #externalMacro(module: "MyMacros", type: "Macro2")
1212
// expected-warning@-1{{external macro implementation type 'MyMacros.Macro2' could not be found for macro 'm2'}}
13-
// expected-note@-2 2{{candidate has partially matching parameter list (Double)}}
13+
// expected-note@-2{{candidate has partially matching parameter list (Double)}}
1414

1515
@m1 struct X1 { }
1616

17-
// FIXME: Redundant diagnostic
18-
@m2 struct X2 { } // expected-error 2{{no exact matches in call to macro 'm2'}}
17+
@m2 struct X2 { } // expected-error{{no exact matches in call to macro 'm2'}}
1918

2019
// Check for nesting rules.
2120
struct SkipNestedType {

0 commit comments

Comments
 (0)