Skip to content

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

@ifreund

Description

@ifreund

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.frontendTokenization, parsing, AstGen, Sema, and Liveness.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.standard libraryThis issue involves writing Zig code for the standard library.zig fmt

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions