Given a struct like this:
struct Set {
uint256 x;
uint256 y;
uint256 expected;
}
It is possible to initialize an instance using a key-value mapping, like this:
Set mySet = Set({ x: 1, y: 2, expected: 3 });
Which is really nice.
Now, suppose that you have an array of structs, defined in the storage of a contract:
contract Foo {
Set[] internal sets;
}
To append an element to the array, we can do this:
sets.push(Set({ x: 1, y: 2, expected: 3 }));
Here’s my feature request - what if you could do the above without the Set(...)
wrapper? What if you could instead write it like this:
sets.push({ x: 1, y: 2, expected: 3 });
The compiler should be able to parse the {}
object, since the compiler knows the type of the array items (always Set
).
The main advantage of enabling this would be enhanced readability (due to fewer parantheses).