mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Parse compound and special names in the macro role attributes (`@freestanding` and `@attached`). This allows both compound names and initializers, e.g., `init(coding:)`. Fixes rdar://107967344.
39 lines
1.5 KiB
Swift
39 lines
1.5 KiB
Swift
@freestanding(expression) public macro publicStringify<T>(_ value: T, label: String? = nil) -> (T, String) = #externalMacro(module: "MacroDefinition", type: "StringifyMacro")
|
|
|
|
@freestanding(expression) public macro unlabeledStringify<T>(_ value: T) -> (T, String) = #publicStringify(value, label: "default label")
|
|
|
|
|
|
@freestanding(expression) macro internalStringify<T>(_ value: T) -> (T, String) = #externalMacro(module: "MacroDefinition", type: "StringifyMacro")
|
|
|
|
@attached(accessor) public macro myWrapper() = #externalMacro(module: "MacroDefinition", type: "MyWrapperMacro")
|
|
|
|
@attached(memberAttribute) public macro wrapAllProperties() = #externalMacro(module: "MacroDefinition", type: "WrapAllProperties")
|
|
|
|
// Make sure that macro custom attributes are not serialized.
|
|
@wrapAllProperties
|
|
public struct S {
|
|
public var value: Int
|
|
}
|
|
|
|
public struct Base {
|
|
public static func member() -> Base { .init() }
|
|
}
|
|
|
|
@attached(memberAttribute) public macro wrapAllProperties(
|
|
_ : Base
|
|
) = #externalMacro(module: "MacroDefinition", type: "WrapAllProperties")
|
|
|
|
@wrapAllProperties(.member())
|
|
public struct TestMacroArgTypechecking {
|
|
public var value: Int
|
|
}
|
|
|
|
@resultBuilder
|
|
public struct Builder {
|
|
public static func buildBlock(_: Int...) -> Void {}
|
|
}
|
|
@freestanding(expression)
|
|
public macro macroWithBuilderArgs(@Builder _: () -> Void) = #externalMacro(module: "A", type: "B")
|
|
|
|
@attached(member, names: named(init(coding:))) public macro ArbitraryMembers() = #externalMacro(module: "MacroDefinition", type: "ArbitraryMembersMacro")
|