Function body macros

Mentioning this per recommendation from this thread - I encountered an issue with the latest Xcode 15 Beta 6 where no existing attached macros can be applied to function parameters.

@URLForm
@POST("/todos/:id/tags")
func createTag(@Path id: Int) async throws // 🛑 'accessor' macro cannot be attached to parameter
@attached(accessor)
public macro Path(_ key: String? = nil) = #externalMacro(module: "PapyrusPlugin", type: "DecoratorMacro")

While it seems like that makes sense for all the existing attached macros - I think there could be some interesting use cases for a macro that allows this; particularly since property wrappers aren't, and likely won't be, allowed at the protocol level.

Would something like this make sense as part of this pitch? For what it's worth my no longer available use case was simply decorating a parameter so that another macro could generate code. I'm not certain of the actual use cases a standalone macro for function parameters might have though perhaps having a generic "decoration" macro that generates nothing is a valid use case.

1 Like