I don't think so. If this was supported it would have to be equivalent to some Any
. But no protocol conformances would be synthesized so the only way you could do anything with this type would be to use reflection to access the stored properties. I can't think of any good use cases for that.
You left off the type annotation on the dictionary here, which would be necessary with anonymous structs. As @Nickolas_Pohilets mentioned, each anonymous struct would be a distinct type. So you would need to use an existential type context. In a hypothetical future version of Swift would would be able to do this:
var d: [any Hashable: String] = [
{[x = 1, y = 1]}: "Hello",
{[x = 2, y = 2]}: "World",
]
The primary limitations of anonymous structs relative to nominals structs are that you can't name the type and they therefore can't be instantiated directly (or more generally, static members can't be used directly). They are only instantiated at the point of the anonymous struct expression, code contained in that expression which uses Self
to name the type, and in generic code which uses initializer requirements. Similarly, static members are only usable in code contained in the anonymous struct expression or in generic code which uses the static member requirements.