SE-0308 was additive because it was a completely new expression node type that fit into the existing ExprSyntax hierarchy. But I don't think this change could be strictly additive for swift-format (or any SwiftSyntax user) because the elements of ArrayElementListSyntax are currently defined to only be ArrayElementSyntax. We'd have to make a breaking change somewhere in the structure, like raising the type of the elements of ArrayElementListSyntax to the type-erased Syntax wrapper so that it could contain either IfConfigDeclSyntaxes or ArrayElementSyntaxes.
This example is even scarier, because in a regular array/dictionary literal, the syntax node that encompasses the square brackets is already typed as an ArrayExprSyntax or DictionaryExprSyntax. If this example were allowed, neither of those would be satisfiable; we'd have to invent something new like an ArrayOrDictionary🤷🏻♂️ExprSyntax to support it.
IMO, I can't think of a non-contrived situation where being able to do the above array/dictionary dance is desirable. The goal of this proposal is to simplify conditionally including/excluding elements from a collection, not to allow a collection to conditionally be either an array or dictionary; I don't think we should allow the latter and if it were allowed I think the complexity would far outweigh the benefit. If an #if is the first thing we hit after a [, I would just determine whether the collection is an array or dictionary based on the first non-#if content that I see, and error out if any of the other blocks don't match that determination.
I'd also like to see some examples involving conditionally empty dictionaries to understand the requirements around how they're expressed, since they have the special [:] syntax. For example, would this be allowed because the content of the #if-block would provide enough context that the whole expression is a dictionary literal?
let dictionary = [
#if FLAG
"foo": 10,
"bar": 20,
#endif
]
Or would this need to be expressed like this instead, because omitting the #if-block would be equivalent to []?
let dictionary = [
#if FLAG
"foo": 10,
"bar": 20,
#else
:
#endif
]
And then how do you square that with more complex cases?
let dictionary = [
#if FLAG1
"foo": 10,
"bar": 20,
#else
:
#endif
#if FLAG2
:
#else
"meep": 30,
"yeex": 40,
#endif
]
I'm supportive of the ideas in this proposal in general, but like others in the thread, I think the write-up needs to be updated a good deal and the implementation needs to be refreshed before it's able to be reviewed.