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

Labeled switch documentation #21383

Merged

Conversation

LiterallyVoid
Copy link
Contributor

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

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 LiterallyVoid force-pushed the literallyvoid/21375-labeled-switch-langref branch from 9c02666 to 2216489 Compare September 11, 2024 06:12
@mlugg
Copy link
Member

mlugg commented Sep 11, 2024

I found that you're able to break out of a switch with an unlabeled break.

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.
@LiterallyVoid LiterallyVoid marked this pull request as ready for review September 12, 2024 02:23
Copy link
Member

@andrewrk andrewrk left a 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.

doc/langref.html.in Outdated Show resolved Hide resolved
@andrewrk andrewrk merged commit cf69154 into ziglang:master Sep 13, 2024
0 of 10 checks passed
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

Successfully merging this pull request may close these issues.

langref docs for labeled switch/continue
3 participants