@@ -77,11 +77,24 @@ public struct FuncFromClosureMacro: DeclarationMacro {
77
77
}
78
78
}
79
79
80
+ public struct FuncFooBarNoAttrsMacro : DeclarationMacro {
81
+ public static var propagateFreestandingMacroAttributes : Bool { false }
82
+ public static var propagateFreestandingMacroModifiers : Bool { false }
83
+
84
+ public static func expansion(
85
+ of node: some FreestandingMacroExpansionSyntax ,
86
+ in context: some MacroExpansionContext
87
+ ) throws -> [ DeclSyntax ] {
88
+ return [ " func foo() -> Int { 1 } " , " func bar() -> String { \" bar \" } " ]
89
+ }
90
+ }
91
+
80
92
//--- test.swift
81
93
82
94
@freestanding ( declaration, names: named ( globalFunc) , named ( globalVar) ) macro globalDecls( ) = #externalMacro( module: " MacroDefinition " , type: " GlobalFuncAndVarMacro " )
83
95
@freestanding ( declaration, names: named ( memberFunc) , named ( memberVar) ) macro memberDecls( ) = #externalMacro( module: " MacroDefinition " , type: " MemberFuncAndVarMacro " )
84
96
@freestanding ( declaration, names: named ( localFunc) , named ( localVar) ) macro localDecls( ) = #externalMacro( module: " MacroDefinition " , type: " LocalFuncAndVarMacro " )
97
+ @freestanding ( declaration, names: named ( foo) , named ( bar) ) macro funcFooBarNoAttrs( ) = #externalMacro( module: " MacroDefinition " , type: " FuncFooBarNoAttrsMacro " )
85
98
86
99
@available ( SwiftStdlib 9999 , * )
87
100
#globalDecls
@@ -157,3 +170,12 @@ struct S2 { // expected-note 4 {{add @available attribute to enclosing struct}}
157
170
}
158
171
}
159
172
}
173
+
174
+ struct S3 {
175
+ @discardableResult private #funcFooBarNoAttrs( )
176
+ }
177
+
178
+ func testS3( value: S3 ) {
179
+ value. foo ( ) // expected-warning {{result of call to 'foo()' is unused}}
180
+ value. bar ( ) // expected-warning {{result of call to 'bar()' is unused}}
181
+ }
0 commit comments