You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@andrewrk on #685 (comment) says that anonymous struct literal should be .{.field = value} instead of {.field = value} because it's like an anonymous enum literal, but for structs/unions.
Anonymous enum literal syntax is fairly seamless. It's just a removal of a type name. .bar is a removal of Foo in Foo.bar.
But this principle does not apply to anonymous struct literals. We need to add a new dot in front of curly braces after remove the type name. So Foo {.bar = 123} becomes .{.bar = 123}.
It may be worth to apply this 'non-anon to anon principle' to struct (and union, array). Like this:
non-anonymous
anonymous
struct literal
Foo.{.bar = 123}
.{.bar = 123}
enum literal
Foo.bar
.bar
Or just remove . for struct literal only (this syntax is debated on #5039):
non-anonymous
anonymous
struct literal
Foo {.bar = 123}
{.bar = 123}
enum literal
Foo.bar
.bar
The text was updated successfully, but these errors were encountered:
Foo.{.bar = 123} was the syntax for a short period for another reason but was then reverted when a different solution was found because people didn't like that syntax: #760
@andrewrk on #685 (comment) says that anonymous struct literal should be
.{.field = value}
instead of{.field = value}
because it's like an anonymous enum literal, but for structs/unions.Anonymous enum literal syntax is fairly seamless. It's just a removal of a type name.
.bar
is a removal ofFoo
inFoo.bar
.But this principle does not apply to anonymous struct literals. We need to add a new dot in front of curly braces after remove the type name. So
Foo {.bar = 123}
becomes.{.bar = 123}
.It may be worth to apply this 'non-anon to anon principle' to struct (and union, array). Like this:
Foo.{.bar = 123}
.{.bar = 123}
Foo.bar
.bar
Or just remove
.
for struct literal only (this syntax is debated on #5039):Foo {.bar = 123}
{.bar = 123}
Foo.bar
.bar
The text was updated successfully, but these errors were encountered: