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
Backing-less enum with a payload variant: an explicit discriminant = N is parsed and silently dropped #1769
A backing-less enum with a payload variant accepts an explicit discriminant = N and drops it: the enum stays a plain ADT enum whose tags are the variant indexes.
enum M:
A = 5
B(i32)
fn mt(m: M) -> i32: m as i32
fn main:
print(mt(M.A))
Prints 0. No diagnostic.
Where
Parser.parse_enum_variants_block parses the = N (parse_disc_value_node) for every variant, but with a payload present it emits the ADT extras format [count, (name, pcount, payloads...)*], which has no discriminant slot, so the value node is never seen by Sema. The comment there says the discriminant is "meaningful only for fieldless enums".
Spec
§4.4a: "Enums can specify an integer representation type and explicit discriminant values for each variant. Discriminant enums use the enum keyword with a representation type"; "Discriminant enums with payloads" are shown with a representation type (enum Msg: i32:). A fieldless enum without one infers i32 (#309), and D71/#1482 makes an @[flags] one a discriminant enum in its default integer representation even with payloads. Whether an explicit = N on a backing-less payload enum makes it a discriminant enum in the inferred i32 (as @[flags] now does) or is an error naming the missing representation type is not written; silently dropping it is neither (No Silent Fallbacks).
Activity
D71 language rulings: @[flags] without repr, from_int on unit enums, …
Parser: an explicit `= N` makes a backing-less payload enum a discrim…
Parser: an explicit `= N` makes a backing-less payload enum a discrim…
Parser: an explicit `= N` makes a backing-less payload enum a discrim…
Spec v7.7 (D75): once parameters, fills, distinct casts, payload disc…