Skip to content

zig fmt: wrong output for empty tagged containers with document comments #23754

@gooncreeper

Description

@gooncreeper

Zig Version

0.15.0-dev.451+a843be44a

Steps to Reproduce and Observed Behavior

Run zig fmt on the following code,

const A = union(enum(u32)) {
    //! Hello World!
};

It incorrectly formats it to

const A = union(enum(u32)) {
    //! Hello World!
//! Hello World!

This applies to packed struct(T), union(T), union(enum(T)), and enum(T)

This happens since Ast.lastToken assumes that when these have no members, the only following tokens are ){}. This also means the bug may also observable in other parts of the compiler, but it is easiest to observe with zig fmt.

Expected Behavior

No change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions