Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match non-anon struct literal syntax with anon #15922

Closed
bangseongbeom opened this issue May 31, 2023 · 3 comments
Closed

Match non-anon struct literal syntax with anon #15922

bangseongbeom opened this issue May 31, 2023 · 3 comments

Comments

@bangseongbeom
Copy link

bangseongbeom commented May 31, 2023

@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
@tauoverpi
Copy link
Contributor

It may also be valuable to have a look at #5038 which would also solve this.

@Vexu
Copy link
Member

Vexu commented Jun 1, 2023

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

@bangseongbeom
Copy link
Author

Thanks for sharing the various syntax proposals! Helped me a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants