Skip to content

StringLiteralExprSyntax adds whitespace in front of closingQuote #2906

Open
@Jeehut

Description

@Jeehut

Description

I'm using version 600.0.1 and wrote this code as part of a macro expression:

      let defaultValueLiteral = StringLiteralExprSyntax(
         openingQuote: .stringQuoteToken(),
         segments: StringLiteralSegmentListSyntax([.stringSegment(.init(content: "Some Text"))]),
         closingQuote: .stringQuoteToken()
      )

When I return it in my ExpressionMacro wrapped into an ExprSyntax, the expanded code looks like this:

"Some Text "

But I expect it to be:

"Some Text"

Am I missing something?

Steps to Reproduce

Here's a more complete code example:

public struct TranslationKey: ExpressionMacro {
   public static func expansion(
      of node: some FreestandingMacroExpansionSyntax,
      in context: some MacroExpansionContext
   ) throws -> ExprSyntax {
      // constructing: `"Some Text"`
      let defaultValueLiteral = StringLiteralExprSyntax(
         openingQuote: .stringQuoteToken(),
         segments: StringLiteralSegmentListSyntax([.stringSegment(.init(content: "Some Text"))]),
         closingQuote: .stringQuoteToken()
      )

      // I have actually more code here (just in case you were wondering)

      return ExprSyntax(defaultValueLiteral)
   }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions