apple / swift-syntax

A set of Swift libraries for parsing, inspecting, generating, and transforming Swift source code.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

ahoppen opened this issue · 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