Skip to content

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

Open

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.

Activity

  1. added
    bug
    on May 3, 2025
  2. changed the title [-]zig fmt: wrong output for empty containers with document comments[/-] [+]zig fmt: wrong output for tagged empty containers with document comments[/+] on May 4, 2025
  3. added a commit that references this issue on May 4, 2025
  4. changed the title [-]zig fmt: wrong output for tagged empty containers with document comments[/-] [+]zig fmt: wrong output for empty tagged containers with document comments[/+] on Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions