Skip to content

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

Closed
@grynspan

Description

@grynspan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    MacrosIssues in the SwiftSyntaxMacro… modulesbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions