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
frontendTokenization, parsing, AstGen, Sema, and Liveness.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.zig fmt
I expected zig fmt to treat @"_" in enum and union(enum) the same:
const A = enum { @"_", _ };
const B = union(enum) { @"_", _ };
The behavior was changed for enums in #15617 (cc @jacobly0).
(Although this seems like an obscure corner case, it actually matters for my project. I'm writing a Markdown parser, and enjoy naming my token variants like .@"* * *" instead of e.g. .thematic_break, since that's a needless extra mapping you have to keep in your head. So I want to use .@"_", not .emphasis.)
The text was updated successfully, but these errors were encountered:
mk12
added
the
bug
Observed behavior contradicts documented or intended behavior
label
Aug 6, 2023
@nektro Could you explain the 👎? This seemed like it was clearly an oversight, to me. I can't think of any rationale for the behavior being different in enums than in tagged unions.
I do wish that people would refrain from using the thumbs down emoji. This isn't a democracy and there is no voting. It just adds negative energy without contributing to the discussion.
Without a use case for having both _ and @"_" fields in a union, I don't see a reason to change zig fmt. The idea is that you can only have the non-canonical form if it has a semantic meaning, and currently putting both _ and @"_" in a union results in error: duplicate union field: '_' (aka, there is currently no such thing as a non-exhaustive tagged union).
Oh interesting, I didn't realize that. I think non-exhaustive tagged unions are useful, so I hope #8162 gets accepted and then my request here should follow. If it gets rejected, then I would instead propose that using _ in a tagged union should be a compile error, just like this already is for variables:
$ echo 'pub fn main() void { var _: bool = true; }' > test.zig
$ zig build-exe test.zig
test.zig:1:26: error: '_' used as an identifier without @"_" syntax
pub fn main() void { var _: bool = true; }
^
That way there's no confusion over whether the _ is special (as it very often is) or just a regular variant name.
As a side note, this might be a point in favor of #4859: using ... to indicate non-exhaustiveness would avoid colliding with anything that could possibly be interpreted as an identifier. Consistently banning _ from use as an identifier in any context (including enum and field names) would also achieve the same goal, I suppose.
jacobly0
added
proposal
This issue suggests modifications. If it also has the "accepted" label then it is planned.
frontend
Tokenization, parsing, AstGen, Sema, and Liveness.
zig fmt
and removed
bug
Observed behavior contradicts documented or intended behavior
labels
Aug 12, 2023
frontendTokenization, parsing, AstGen, Sema, and Liveness.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.zig fmt
Zig Version
0.12.0-dev.5+fc6e57568
Steps to Reproduce and Observed Behavior
Expected Behavior
I expected zig fmt to treat
@"_"
inenum
andunion(enum)
the same:The behavior was changed for enums in #15617 (cc @jacobly0).
(Although this seems like an obscure corner case, it actually matters for my project. I'm writing a Markdown parser, and enjoy naming my token variants like
.@"* * *"
instead of e.g..thematic_break
, since that's a needless extra mapping you have to keep in your head. So I want to use.@"_"
, not.emphasis
.)The text was updated successfully, but these errors were encountered: