Skip to content
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

SyntaxProtocol.expand(macros:) drops IfConfigDeclSyntax nodes from result #2923

Open
grynspan opened this issue Dec 20, 2024 · 1 comment
Open
Labels
bug Something isn't working Macros Issues in the SwiftSyntaxMacro… modules

Comments

@grynspan
Copy link
Contributor

Description

Given the following code:

let sourceCode = """
#if true
@inlinable
#endif
func f() {}
"""

let originalSyntax = Parser.parse(source: sourceCode)
print(originalSyntax)
let context = BasicMacroExpansionContext(lexicalContext: [], expansionDiscriminator: "", sourceFiles: [:])
let syntax = originalSyntax.expand(macros: [:]) { syntax in
  BasicMacroExpansionContext(sharingWith: context, lexicalContext: syntax.allMacroLexicalContexts())
}
print(syntax)

I would expect to see (ignoring potential reformatting):

#if true
@inlinable
#endif
func f() {}

But syntax drops everything in the IfConfigDeclSyntax node (#if onward) and just produces:

func f() {}

originalSyntax is correct, so the issue is during macro expansion, not the initial parse.

Steps to Reproduce

See above.

@grynspan grynspan added bug Something isn't working Macros Issues in the SwiftSyntaxMacro… modules labels Dec 20, 2024
@ahoppen
Copy link
Member

ahoppen commented Dec 20, 2024

Synced to Apple’s issue tracker as rdar://141840779

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Macros Issues in the SwiftSyntaxMacro… modules
Projects
None yet
Development

No branches or pull requests

2 participants