Let's say you have a macro declaration like this:
public macro AddCompletionHandler(completionName: String = "onCompletion") = #externalMacro(...)
and you use it omitting the
@AddCompletionHandler() public func whatever(...
When this macro is tried to be expanded, the code in the macro receives an
AttributeSyntax with no parameters, and of course with no reference to the default value defined in the macro declaration. I guess that in this case you must search for the parameter in the
AttributeSyntax, and if not present, assume a default value...
But where do you define this default value??? I only see two options:
- You create a magic value inside the macro implementation which is used as the default value of the parameter (I would call this magic even if defined as a constant anywhere, because it is totally unrelated to the value in the macro declaration, and a change in the macro declaration without a corresponding change in the macro implementation would cause the macro to have inconsistent behaviour)
- Create a constant in the macro implementation that is used in the macro declaration. This feels unnatural because you would be using a constant defined elsewhere as a default value, and you would probably be forced to give access to the source code of the macro, something that you may not want to do
Am I missing anything here?