-
Notifications
You must be signed in to change notification settings - Fork 378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
makeUniqueName() produces tokens that cannot be used as closure arguments #2256
Comments
See also apple/swift#68475 |
|
Having a day here… :) The issue with the spurious error is fixed, but I still can't use |
Tracked in Apple’s issue tracker as rdar://116402749 |
Reduced reproducer public struct StringifyMacro: ExpressionMacro {
public static func expansion(
of node: some FreestandingMacroExpansionSyntax,
in context: some MacroExpansionContext
) -> ExprSyntax {
guard let argument = node.argumentList.first?.expression else {
fatalError("compiler bug: the macro does not have any arguments")
}
let arg0 = context.makeUniqueName("")
return """
{ \(arg0) in
return \(argument)
}(1)
"""
}
} Usage _ = #stringify(a + b) Expands to the following, which doesn’t compile _ = { $s17mac_adsfjlkClient33_E5FD3D533106409A33F51D71F9BB5B8CLl9stringifyfMf_7__localfMu_ in
return a + b
}(1) |
Description
If I attempt to label closure arguments during macro expansion:
The compiler complains:
This means I can't reliably produce closure argument names, which is problematic if my macro expansion generates a closure and the macro is being used inside another closure:
Steps to Reproduce
See above.
The text was updated successfully, but these errors were encountered: