swiftlang/swift-syntax

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

ahoppen opened this issue · 1 comments

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.

Tracked in Apple’s issue tracker as rdar://122346869