Skip to content

Generic enum carrying H[T] of another generic enum: binding the payload in a match fails MIR validation #1442

Closed

Description

@ehartford

Summary

A generic enum whose payload is another generic enum instantiated with the same parameter fails MIR validation when the payload is bound in a match.

Repro (origin/main 1c76062)

enum H[T]:
    X(t: T)
    Y

enum G[T]:
    A(h: H[T])
    B(n: i64)

fn show_h(h: H[i64]):
    match h:
        H.X(t) => print(f"X {t}")
        H.Y => print("Y")

fn main:
    let g: G[i64] = G.A(H.X(3))
    match g:
        G.A(h) => show_h(h)
        G.B(n) => print(f"B {n}")
error: invalid MIR before codegen: use rvalue type is incompatible with assign destination (dest ty=427 kind=19, src ty=4 kind=1)
 --> e18.w:17:13
17 |         G.A(h) => show_h(h)

Expected: X 3. (src ty=4 is TY_VOID: the bound payload's type did not resolve through the substitution T -> i64 of the nested instance.) A non-generic enum carrying H[i64] works (after #1430).

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