Skip to content

Commit b5062bd

Browse files
authored
Merge pull request #66417 from rintaro/macros-attrpropagation-rdar110364154
[Macros] Test case for opt-out from automatic attrs propagation
2 parents 65e37f7 + d51bbef commit b5062bd

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/Macros/macro_attribute_expansiondecl.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)