Skip to content

Incorrect indentation added to macro that doesn’t start on a new line #2473

@ahoppen

Description

@ahoppen

The following new test case fails.

public struct TestMacro: ExpressionMacro {
  public static func expansion(of node: some FreestandingMacroExpansionSyntax, in context: some MacroExpansionContext) throws -> ExprSyntax {
    return "1"
  }
}

func testMacroAsArgument() {
  assertMacroExpansion("""
  func test() {
    print(#test)
  }
  """, expandedSource: """
  func test() {
    print(1)
  }
  """, macros: ["test": TestMacro.self])
}

Instead, it produces print( 1), adding the indentation of the print line to the macro expansion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    MacrosIssues in the SwiftSyntaxMacro… modules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions