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

Undesireable zig fmt behavior with while statement nested in blockless if #6114

Closed
ifreund opened this issue Aug 21, 2020 · 0 comments
Closed
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. standard library This issue involves writing Zig code for the standard library. zig fmt
Milestone

Comments

@ifreund
Copy link
Member

ifreund commented Aug 21, 2020

zig fmt currently allows either of the following:

pub fn main() void {
    const zoom_node = if (focused_node == layout_first) while (it.next()) |node| {
        if (!node.view.pending.float and !node.view.pending.fullscreen) break node;
    } else null else focused_node;
}
pub fn main() void {
    const zoom_node = if (focused_node == layout_first) while (it.next()) |node| {
        if (!node.view.pending.float and !node.view.pending.fullscreen) break node;
    } else null else
        focused_node;
}

Ideally, I think that it should allow something like this:

pub fn main() void {
    const zoom_node = if (focused_node == layout_first)
        while (it.next()) |node| {
            if (!node.view.pending.float and !node.view.pending.fullscreen) break node;
        } else null
    else
        focused_node;
}

This can be worked around by using a labeled block for the first arm of the if statement, but labels are quite verbose.

@Vexu Vexu added standard library This issue involves writing Zig code for the standard library. frontend Tokenization, parsing, AstGen, Sema, and Liveness. enhancement Solving this issue will likely involve adding new logic or components to the codebase. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. labels Aug 21, 2020
@Vexu Vexu added this to the 0.8.0 milestone Aug 21, 2020
LakeByTheWoods added a commit to LakeByTheWoods/zig that referenced this issue Aug 30, 2020
LakeByTheWoods added a commit to LakeByTheWoods/zig that referenced this issue Aug 30, 2020
LakeByTheWoods added a commit to LakeByTheWoods/zig that referenced this issue Sep 9, 2020
@andrewrk andrewrk added proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. and removed contributor friendly This issue is limited in scope and/or knowledge of Zig internals. labels Sep 17, 2020
ifreund added a commit to LewisGaul/zig that referenced this issue Mar 15, 2021
The main realization here was that getting rid of the early returns
in renderWhile() and rewriting the logic into a mostly unified execution
path took things from ~200 lines to ~100 lines and improved consistency
by deduplicating code.

Also add several test cases and fix a few issues along the way:

Fixes ziglang#6114
Fixes ziglang#8022
LewisGaul pushed a commit to LewisGaul/zig that referenced this issue Mar 15, 2021
The main realization here was that getting rid of the early returns
in renderWhile() and rewriting the logic into a mostly unified execution
path took things from ~200 lines to ~100 lines and improved consistency
by deduplicating code.

Also add several test cases and fix a few issues along the way:

Fixes ziglang#6114
Fixes ziglang#8022
rgreenblatt pushed a commit to rgreenblatt/zig that referenced this issue Mar 19, 2021
The main realization here was that getting rid of the early returns
in renderWhile() and rewriting the logic into a mostly unified execution
path took things from ~200 lines to ~100 lines and improved consistency
by deduplicating code.

Also add several test cases and fix a few issues along the way:

Fixes ziglang#6114
Fixes ziglang#8022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. standard library This issue involves writing Zig code for the standard library. zig fmt
Projects
None yet
Development

No branches or pull requests

3 participants