- Notifications
You must be signed in to change notification settings - Fork10.6k
Open
Description
Description
I use macro to create global constant string, it success.
But, when I use a nested macro to wrap#flat macro, it build success and expand as expected in XCode, but the constant string did not appears in mach-o file. (I usedXMachOViewer to check executable binary file)


Reproduction
Attached is a reduced package that reproduces the behavior:
Test.zip
publicstructFlatMacro:DeclarationMacro{publicstaticfunc expansion( of node:someSwiftSyntax.FreestandingMacroExpansionSyntax, in context:someSwiftSyntaxMacros.MacroExpansionContext)throws->[DeclSyntax]{letargumentList= node.argumentsvarname:String=""forargumentin argumentList{switch argument.label?.text{case"name":iflet stringLiteral= argument.expression.as(StringLiteralExprSyntax.self),let hostValue= stringLiteral.segments.first?.as(StringSegmentSyntax.self)?.content.text{ name= hostValue}default:break}}letvarName="\(context.makeUniqueName("flat"))"letdeclarationString=""" let\(varName) ="~~~~\(name)""""return[DeclSyntax(stringLiteral: declarationString)]}}publicstructNestedMacro:DeclarationMacro{publicstaticfunc expansion( of node:someSwiftSyntax.FreestandingMacroExpansionSyntax, in context:someSwiftSyntaxMacros.MacroExpansionContext)throws->[DeclSyntax]{return[""" #flat(name:"456")"""]}}
Expected behavior
The global constant "~~~~456" will be compiled to the mach-o binary file.
Environment
swift 6.0
Additional information
No response