I'm trying to create macro that has an optional closure argument. I'll simplify.
The interface looks like this:
@freestanding(expression)
public macro myMacro(closure: (()->())? = nil) -> Void = #externalMacro(module: "MyMacrosImplementation", type: "MyMacro")
My macro unit tests work as expected, with both the 0 argument and 1 argument test cases. But tests in actual code are not working as expected. For example, when I do:
#myMacro(closure: {
print("Hello, World")
})
it behaves as if no closure argument was passed. And Xcode isn't allowing me to see the expansion.
Update: I've figured this out. It had to do with the way I was testing. I was using the macro from top level code and that produced odd behavior. Here's test code that works as expected. TestMacroArgs2.zip - Google Drive