Skip to content

Commit 9691060

Browse files
committed
[Diagnostics] Add declaration name to macro_attached_to_invalid_decl
This could also use `%kind` for the declaration kind, but that ends up being "extension of struct" instead of just "extension", which seems slightly worse.
1 parent 18cb5f4 commit 9691060

File tree

6 files changed

+10
-11
lines changed

6 files changed

+10
-11
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7232,8 +7232,8 @@ ERROR(extension_macro_invalid_conformance,none,
72327232
"invalid protocol conformance %0 in extension macro",
72337233
(Type))
72347234
ERROR(macro_attached_to_invalid_decl,none,
7235-
"'%0' macro cannot be attached to %1",
7236-
(StringRef, DescriptiveDeclKind))
7235+
"'%0' macro cannot be attached to %1 (%base2)",
7236+
(StringRef, DescriptiveDeclKind, const Decl *))
72377237
ERROR(conformance_macro,none,
72387238
"conformance macros are replaced by extension macros",
72397239
())

lib/Sema/TypeCheckAttr.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3688,10 +3688,9 @@ void AttributeChecker::visitCustomAttr(CustomAttr *attr) {
36883688
for (auto *roleAttr : macro->getAttrs().getAttributes<MacroRoleAttr>()) {
36893689
auto role = roleAttr->getMacroRole();
36903690
if (isInvalidAttachedMacro(role, D)) {
3691-
diagnoseAndRemoveAttr(attr,
3692-
diag::macro_attached_to_invalid_decl,
3691+
diagnoseAndRemoveAttr(attr, diag::macro_attached_to_invalid_decl,
36933692
getMacroRoleString(role),
3694-
D->getDescriptiveKind());
3693+
D->getDescriptiveKind(), D);
36953694
}
36963695
}
36973696

test/Macros/accessor_macros.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,5 @@ struct MyBrokenStruct {
114114

115115
@myPropertyWrapper
116116
struct CannotHaveAccessors {}
117-
// CHECK-DIAGS: 'accessor' macro cannot be attached to struct
117+
// CHECK-DIAGS: 'accessor' macro cannot be attached to struct ('CannotHaveAccessors')
118118
#endif

test/Macros/macro_expand_attributes.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ expansionOrder.originalMember = 28
144144
#if TEST_DIAGNOSTICS
145145
@wrapAllProperties
146146
typealias A = Int
147-
// expected-error@-2{{'memberAttribute' macro cannot be attached to type alias}}
147+
// expected-error@-2{{'memberAttribute' macro cannot be attached to type alias ('A')}}
148148

149149
@wrapAllProperties
150150
func noMembers() {}
151-
// expected-error@-2{{'memberAttribute' macro cannot be attached to global function}}
151+
// expected-error@-2{{'memberAttribute' macro cannot be attached to global function ('noMembers')}}
152152
#endif

test/Macros/macro_expand_extensions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ func testLocal() {
113113

114114
@DelegatedConformance
115115
typealias A = Int
116-
// expected-error@-2 {{'extension' macro cannot be attached to type alias}}
116+
// expected-error@-2 {{'extension' macro cannot be attached to type alias ('A')}}
117117

118118
@DelegatedConformance
119119
extension Int {}
120-
// expected-error@-2 {{'extension' macro cannot be attached to extension}}
120+
// expected-error@-2 {{'extension' macro cannot be attached to extension (extension of 'Int')}}
121121

122122
@attached(extension, conformances: P)
123123
macro UndocumentedNamesInExtension() = #externalMacro(module: "MacroDefinition", type: "DelegatedConformanceViaExtensionMacro")

test/Macros/macro_expand_peers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func testVarPeer() {
217217
#if TEST_DIAGNOSTICS
218218
// Macros cannot be attached to function parameters
219219

220-
// expected-error@+1{{'peer' macro cannot be attached to parameter}}
220+
// expected-error@+1{{'peer' macro cannot be attached to parameter ('x')}}
221221
func test(@declareVarValuePeer x: Int) {}
222222
#endif
223223

0 commit comments

Comments
 (0)