You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
@[flags] on a backing-less enum is silently ignored (0,1,2); spec does not say whether it doubles or requires a repr #1482
@[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.
@[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
Discriminants are i64 end to end: Sema computes them from the literal…
Discriminants are i64 end to end: Sema computes them from the literal…
Discriminants are i64 end to end: Sema computes them from the literal…
D71 language rulings: @[flags] without repr, from_int on unit enums, …
Sema: generic enum walkers read the discriminant enum layout too, bec…
Parser: an explicit `= N` makes a backing-less payload enum a discrim…
Sema: generic enum walkers read the discriminant enum layout too, bec…
Parser: an explicit `= N` makes a backing-less payload enum a discrim…
Sema: generic enum walkers read the discriminant enum layout too, bec…
Parser: an explicit `= N` makes a backing-less payload enum a discrim…
Enums: payload discriminants, casts, generic layouts, and fn-type com…