Skip to content

zig fmt: format else branch with anon struct literal without extra line break #8022

@andrewrk

Description

@andrewrk

desired:

    const else_info: struct {
        src: usize,
        result: ?*zir.Inst,
    } = if (else_node != 0) blk: {
        block_scope.break_count += 1;
        const sub_scope = &else_scope.base;
        break :blk .{
            .src = token_starts[tree.lastToken(else_node)],
            .result = try expr(mod, sub_scope, block_scope.break_result_loc, else_node),
        };
    } else .{
        .src = token_starts[tree.lastToken(if_full.then_expr)],
        .result = null,
    };

however zig fmt does this:

    const else_info: struct {
        src: usize,
        result: ?*zir.Inst,
    } = if (else_node != 0) blk: {
        block_scope.break_count += 1;
        const sub_scope = &else_scope.base;
        break :blk .{
            .src = token_starts[tree.lastToken(else_node)],
            .result = try expr(mod, sub_scope, block_scope.break_result_loc, else_node),
        };
    } else
        .{
            .src = token_starts[tree.lastToken(if_full.then_expr)],
            .result = null,
        };

it messes with the else branch.

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.zig fmt

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions