I’m using SwiftSyntax 0.50200.0, and I cannot seem to find a way to coax a WithTrailingCommaSyntax
existential back into a Syntax
instance.
class Rewriter: SyntaxRewriter {
override func visitAny(_ node: Syntax) -> Syntax? {
if let entry = node.asProtocol(WithTrailingCommaSyntax.self),
entry.trailingComma != nil,
entry.indexInParent == entry.parent?.children.last?.indexInParent {
let modified = entry.withTrailingComma(nil)
return Syntax(modified) // Error: “Value of protocol type 'WithTrailingCommaSyntax' cannot conform to 'SyntaxProtocol'; only struct/enum/class types can conform to protocols”
} else {
return node
}
}
}
I discovered return modified._syntaxNode
works, but that’s an underscored API and its documentation says not to use it, but instead to do what doesn’t work above.
What’s the right way to do this?