Anonymous Structs

The quick style of initialization of anonymous structs reminds me of creating a class in Kotlin. That being said, maybe the { ( ... ) } syntax would be a good idea. Also, since properties would have their name and then an = operator, followed by their value, they would be different from tuples who use a : to separate their argument names from their values. This also avoids the possibility of the anonymous struct being confused for a capture list.

Also, I don't really think that there is any point in restricting the declaration of stored properties in an anonymous struct to within the ( ... ) part of it. I think you should be able to either succinctly declare it in the list at the top or in its body, as long as it meets the protocol requirements and all stored properties are given a value.

I was thinking that all of the following should all be equivalent (eq1, eq2, eq3, eq4, eq5):

protocol Foo {
    var x: Int { get }
    var y: String { get set }
}

var eq1: some Foo & Equatable = { (x = 4, var y = "Hello") }
var eq2: some Foo & Equatable = { (var y = "Hello", x = 4) }
var eq3: some Foo & Equatable = { (x = 4) in
    var y = "Hello"
}
var eq4: some Foo & Equatable = { (var y = "Hello") in
    let x = 4 
}
var eq5: some Foo & Equatable = {
    let x = 4 
    var y = "Hello"
}

I wasn't totally sure about whether or not to include in, but I think it makes sense if it is only required if the ( ... ) part of the declaration is either the only part of the declaration, or is empty (as shown in eq1, eq2, and eq5). Also, I see no reason to disallow (let x = 4), (private(set) var x = 4), or any other modifier for that matter as long as it satisfies the protocol requirements. I think that let should be implicit, but if it—or anything else that satisfies the protocol requirement—is provided, I don't see any reason for the compiler to complain.

Also, to make clear the separation between property names and values that share a common name, I feel like it would be useful to always require the property name and the value separated by = for each property. In the following example, though the property in the protocol shares a common name with a global variable, the property name must always be stated in the declaration of an anonymous struct (baz1, baz2, baz3, baz4, and baz5 would all be considered valid declarations under all of the aforementioned rules):

protocol Bar {
    var a: Int { get }
}

var a = 24
let baz1: some Bar = { (a = a) }
let baz2: some Bar = { (private(set) var a = a) }
let baz3: some Bar = { (var a = a) }
let baz4: some Bar = { (let a = a) }
let baz5: some Bar = { 
    let a = a
}
let baz6: some Bar = { (a) } // Error: a value must be provided to each stored property of an anonymous struct.

Grammar:

declaration-headattributesopt declaration-modifiersopt var
declaration-headattributesopt declaration-modifiersopt let
declaration-headattributesopt declaration-modifiers
declaration-headattributes

property-nameidentifier

anonymous-struct-property → declaration-headopt property-name type-annotation = expression
anonymous-struct-property → declaration-headopt property-name = expression

anonymous-struct-property-list → anonymous-struct-property | anonymous-struct-property , anonymous-struct-property-list

anonymous-struct-property-declaration( anonymous-struct-property-list )

anonymous-struct-declaration{ anonymous-struct-property-declaration }
anonymous-struct-declaration{ anonymous-struct-property-declaration in struct-body }
anonymous-struct-declaration{ struct-body }