Skip to content

@[flags] on a backing-less enum is silently ignored (0,1,2); spec does not say whether it doubles or requires a repr #1482

Closed

Description

@ehartford

Summary

@[flags] on a backing-less fieldless enum is silently ignored: the variants auto-increment 0, 1, 2 instead of doubling. The spec does not say which is right, so this needs a ruling.

Repro (installed nightly v0.15.2.1; origin/main ba2d5d1 stage1)

@[flags]
enum G:
    X
    Y
    Z

fn main:
    print(f"{G.X as i32} {G.Y as i32} {G.Z as i32}")

Prints 0 1 2. With an explicit repr (enum G: i32:) the same body prints 1 2 4.

Spec text

§4.4a: "@[flags] attribute: For bitflag enums, @[flags] changes auto-increment to power-of-two doubling" — shown on enum Perms: i32:. For @[specified] the spec rules the backing-less case ("@[specified] requires an explicit integer representation type", and the parser rejects it). The compiler gives a fieldless backing-less enum an inferred i32 backing and treats it as a discriminant enum (#309), but the spec does not say whether that makes it a "bitflag enum" @[flags] applies to.

The question

Either @[flags] doubles on a backing-less enum too (it is a discriminant enum with an inferred i32), or it requires an explicit repr and is rejected like @[specified]. Silently ignoring the attribute is neither.

Found while fixing #1451 (Sema now computes auto-increments; the #1451 fix keeps the old behavior here until this is ruled).

Activity

  1. added 8 commits that reference this issue on Sep 27, 2026
    d52a6ab
    6866f2c
    dd8b527
    779139b
    3a630fd
    3c7708c
    63be345
    29f38f6
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions