-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Labeled switch documentation #21383
Merged
andrewrk
merged 20 commits into
ziglang:master
from
LiterallyVoid:literallyvoid/21375-labeled-switch-langref
Sep 13, 2024
Merged
Labeled switch documentation #21383
andrewrk
merged 20 commits into
ziglang:master
from
LiterallyVoid:literallyvoid/21375-labeled-switch-langref
Sep 13, 2024
+139
−0
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This feature was proposed in ziglang#8220, and implemented in ziglang#21257.
After testing, `break` does not target an unlabeled `switch`. However, it *can* target a labeled switch, even if the `break` is unlabeled. This behavior seems surprising and worth a callout, although this may not be the place for it.
This paragraph was copied from the release notes, written by @mlugg.
As before, text has been adapted from the release notes, which were written by @mlugg.
LiterallyVoid
force-pushed
the
literallyvoid/21375-labeled-switch-langref
branch
from
September 11, 2024 06:12
9c02666
to
2216489
Compare
LiterallyVoid
commented
Sep 11, 2024
LiterallyVoid
commented
Sep 11, 2024
LiterallyVoid
commented
Sep 11, 2024
Oh shit, that's definitely a bug, thank you for pointing it out. I'll get a fix up shortly. EDIT: see #21385 |
I'm also moving away from "statement" here. Break is actually an expression, and while it's almost impossible to observe this in code that doesn't have any compiler errors, it can be shown: test "a" { _ = while (true) { _ = break 42; }; } Nevertheless, `break` is still described as a statement in the Zig docs. It may be that the Zig docs simply take statement to mean something else---it says, "compile log statements", later in the document.
I've tried to cram as many concepts in as few lines as possible. I've also split the desugaring into its own test---the names here are bad, and I'll improve them soon.
This comment was moved here from the other switch continue example, as that one no longer shows switch having a result value.
andrewrk
requested changes
Sep 13, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I'll see if I can use github's UI to merge this along with my edit right now.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Feel free to nitpick wording and examples, especially mine---the good parts have been copied from @mlugg's release notes!
In particular, I found that you're able to break out of a switch with an unlabeled break. This was really surprising, and may be better disallowed than noted in the docs.
Closes #21375