@@ -77,11 +77,24 @@ public struct FuncFromClosureMacro: DeclarationMacro {
7777 }
7878}
7979
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+
8092//--- test.swift
8193
8294@freestanding ( declaration, names: named ( globalFunc) , named ( globalVar) ) macro globalDecls( ) = #externalMacro( module: " MacroDefinition " , type: " GlobalFuncAndVarMacro " )
8395@freestanding ( declaration, names: named ( memberFunc) , named ( memberVar) ) macro memberDecls( ) = #externalMacro( module: " MacroDefinition " , type: " MemberFuncAndVarMacro " )
8496@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 " )
8598
8699@available ( SwiftStdlib 9999 , * )
87100#globalDecls
@@ -157,3 +170,12 @@ struct S2 { // expected-note 4 {{add @available attribute to enclosing struct}}
157170 }
158171 }
159172}
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