Skip to content

Generic discriminant enum with a payload variant: invalid MIR before codegen (payload type unresolved) #1768

Closed

Description

@ehartford

A generic discriminant enum (explicit representation type) with a payload variant reaches MIR with its payload type unresolved.

Repro (stage1 of main 09a0efb)

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.

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