Hi! I've been experimenting with an accessor
macro to synthesize a getter and setter on an arbitrary property. Things are working fine for me with this declaration:
@attached(accessor)
public macro PropertyMacroGetterAndSetter(...)
According to the Swift Book documentation on the attached
attribute:[1]:
The peer, member, and accessor macro roles require a
names:
argument, listing the names of the symbols that the macro generates.
Which seems to imply that an attached
attribute on an accessor
macro should fail to synthesize a getter and setter (assuming I have not explicitly specified the names
).
If I try:
@attached(accessor, names: named(get))
public macro PropertyMacroGetterAndSetter(...)
I am still getting my getter and setter synthesized… which is weird (because I only specify get
but this does not block me on synthesizing a set
). Is swift-syntax
not respecting those names
being passed? Is @attached(accessor)
the legit declaration (and the documentation that tells us names
must be passed is out-of-date)?
Here is a simple patch diff on swift-syntax
that shows this in action:
diff --git a/Examples/Sources/MacroExamples/Interface/ComplexMacros.swift b/Examples/Sources/MacroExamples/Interface/ComplexMacros.swift
index da160c99..e4e82d29 100644
--- a/Examples/Sources/MacroExamples/Interface/ComplexMacros.swift
+++ b/Examples/Sources/MacroExamples/Interface/ComplexMacros.swift
@@ -24,7 +24,7 @@
@attached(member, names: named(_storage))
public macro DictionaryStorage() = #externalMacro(module: "MacroExamplesImplementation", type: "DictionaryStorageMacro")
-@attached(accessor)
+@attached(accessor, names: named(get))
public macro DictionaryStorageProperty() =
#externalMacro(module: "MacroExamplesImplementation", type: "DictionaryStoragePropertyMacro")