Skip to content

[5.9][Macros] Test case for opt-out from automatic attrs propagation #66419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions test/Macros/macro_attribute_expansiondecl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,24 @@ public struct FuncFromClosureMacro: DeclarationMacro {
}
}

public struct FuncFooBarNoAttrsMacro: DeclarationMacro {
public static var propagateFreestandingMacroAttributes: Bool { false }
public static var propagateFreestandingMacroModifiers: Bool { false }

public static func expansion(
of node: some FreestandingMacroExpansionSyntax,
in context: some MacroExpansionContext
) throws -> [DeclSyntax] {
return ["func foo() -> Int { 1 }", "func bar() -> String { \"bar\" }"]
}
}

//--- test.swift

@freestanding(declaration, names: named(globalFunc), named(globalVar)) macro globalDecls() = #externalMacro(module: "MacroDefinition", type: "GlobalFuncAndVarMacro")
@freestanding(declaration, names: named(memberFunc), named(memberVar)) macro memberDecls() = #externalMacro(module: "MacroDefinition", type: "MemberFuncAndVarMacro")
@freestanding(declaration, names: named(localFunc), named(localVar)) macro localDecls() = #externalMacro(module: "MacroDefinition", type: "LocalFuncAndVarMacro")
@freestanding(declaration, names: named(foo), named(bar)) macro funcFooBarNoAttrs() = #externalMacro(module: "MacroDefinition", type: "FuncFooBarNoAttrsMacro")

@available(SwiftStdlib 9999, *)
#globalDecls
Expand Down Expand Up @@ -157,3 +170,12 @@ struct S2 { // expected-note 4 {{add @available attribute to enclosing struct}}
}
}
}

struct S3 {
@discardableResult private #funcFooBarNoAttrs()
}

func testS3(value: S3) {
value.foo() // expected-warning {{result of call to 'foo()' is unused}}
value.bar() // expected-warning {{result of call to 'bar()' is unused}}
}