Description
Currently SwiftBasicFormat will format try? as try ?, which is a false syntax rejected by the Swift compiler.
Steps to Reproduce
import SwiftSyntax
import SwiftSyntaxBuilder
import SwiftBasicFormat
class CodeGenerationFormat: BasicFormat {
override var indentation: TriviaPiece { .spaces(indentationLevel * 2) }
}
let sourceFile = SourceFile {
ImportDecl("import Foundation")
VariableDecl("let url = URL(string: \"https://www.swift.org\")")
VariableDecl("let content = try? String(contentsOf: url)")
}
print(sourceFile.formatted(using: CodeGenerationFormat()))
Output:
import Foundation
let url = URL(string: "https://www.swift.org")
let content = try ? String(contentsOf: url)
// main.swift:3:18 Consecutive statements on a line must be separated by ';'
// main.swift:3:19 Expected initial value after '='
// main.swift:3:19 Expected expression
Description
Currently
SwiftBasicFormatwill formattry?astry ?, which is a false syntax rejected by the Swift compiler.Steps to Reproduce
Output: