-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
if
without braces in switch case is parsed weirdly
#3749
Comments
also works: pub fn main() void {
var blah = false;
var x = false;
switch (x) {
false => { if (blah) x = true; },
true => { if (blah) x = false; },
}
} |
I'm guessing that without braces, the switch is looking for a return value and convinces the |
This works fine, so maybe the problem is limited to when you have an assignment in the if clause? fn func() void {
var x = false;
}
pub fn main() void {
var blah = false;
var x = false;
switch (x) {
false => if (blah) func(),
true => if (blah) func() else func(),
}
} |
Related #5731. |
I humbly suggest that It's one of the biggest footguns in C where the first line is in the if (true)
std.debug.writeAll("it's true!\n")
std.debug.writeAll("no really, it's true\n") |
Self-hosted gives a nicer error for this:
Proposal to change the grammar in #5731 |
I'm not really sure what the parser is trying to do here. I think this should work. I don't think the comma is overloaded that much in Zig so I don't see any ambiguity.
It works if I add curly braces to the if's.
And this:
Yields this:
The text was updated successfully, but these errors were encountered: