SwiftSyntax: how to repair abbreviated function signatures?

i think everyone is familiar with abbreviated function signatures from places like DocC documentation (although DocC doesn’t actually generate them, the swift compiler generates them.)

here’s an example:

init(String.Index, x:(Int) -> Int) rethrows

i’ve wasted far more time than i would like to admit trying to get SwiftSyntax to understand them, but because unlabeled parameters aren’t prefixed with the usual _: tokens, SwiftSyntax just doesn’t consider them well-formed syntax:

if you try pasting the signature above into a tool like https://swift-ast-explorer.com/ , you will see that the syntax tree is completely broken:

i’ve tried a few absurd hacks to try and help SwiftSyntax digest these signatures, but there just doesn’t seem to be a way to work around the fact that lib/SymbolGraphGen¹ doesn’t emit well-formed signatures.

how can i repair these signatures so that SwiftSyntax can understand them?

[1] these days there are just so, so, so, so, so, so, so many lib/SymbolGraphGen bugs. this part of the compiler must be cursed…

1 Like

I think the solution here would be that swift-syntax should be better at recovering function parameters that don’t have a type annotation, i.e. it should get parsed as a syntax tree with a missing identifier for the first name and a missing colon. Could you file an issue at Issues · apple/swift-syntax · GitHub?


done: swift syntax should be able to recover function parameters without argument labels · Issue #2254 · apple/swift-syntax · GitHub