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
Generic discriminant enum with a payload variant: invalid MIR before codegen (payload type unresolved) #1768
enum E[T]: i32:
A = 3
B(T) = 5
fn main:
let b: E[i64] = E.B(40)
match b:
E.B(v) =>
let w: i64 = v + 2
print(w)
_ => print("other")
error: invalid MIR before codegen: use rvalue does not resolve to a concrete MIR type (place local=1 local_ty=1804 projs=2 proj0_kind=3)
--> gen2.w:8:13
8 | E.B(v) =>
The same enum without the representation type (enum E[T]:) prints 42. print(v) in the arm instead reports cannot infer type parameter 'T' for this call.
Spec
§4.4a: "Discriminant enums with payloads: Variants can carry associated data just like regular enums, combined with explicit discriminant values." Nothing excludes a generic one. A post-Sema invalid MIR on a program Sema accepted is a compiler bug (D65).
Where
The AST of a discriminant enum is in the disc-enum extras format (repr, count, (name, disc, pcount, payloads...)*, Parser.parse_disc_enum_variants_*); SemaDecl's DiscEnum branch resolves payload types without the generic handling the plain Enum branch has (is_generic_decl). Not yet located at the instruction level.
Why it matters now
D71 / §4.4a (#1482): an @[flags] enum with no representation type doubles in its default integer representation; the #1482 fix makes a backing-less @[flags] enum a discriminant enum with an inferred i32. For a generic enum with a payload variant that would hit this bug, so the #1482 fix rejects @[flags] there with an error naming this issue until it is fixed.
Activity
D71 language rulings: @[flags] without repr, from_int on unit enums, …
Sema: generic enum walkers read the discriminant enum layout too, bec…
Sema: generic enum walkers read the discriminant enum layout too, bec…
Sema: generic enum walkers read the discriminant enum layout too, bec…