Skip to content

Payload discriminant enums with non-index discriminants fail codegen: 'aggregate enum payload missing destination payload type' #1455

Closed

Description

@ehartford

Spec: §4.4a ("Discriminant enums with payloads: Variants can carry associated data just like regular enums, combined with explicit discriminant values"; the layout is { repr_ty, [max_payload_size x i8] } "with the tag being the discriminant value").

A payload-carrying discriminant enum whose discriminants are not 0, 1, 2, … fails code generation:

enum Msg: i32:
    Quit = 0
    Move(i32, i32) = 7

fn main:
    let m = Msg.Move(1, 2)
    match m:
        .Quit => print("q")
        .Move(x, y) => print(x + y)
error: aggregate enum payload missing destination payload type fn=main variant=7
error: code generation failed

The discriminant value (7) is used where the variant index (1) is expected when the aggregate's payload type is looked up. The same with u8 repr and Write(str) = 200. With discriminants 0, 1, 2 it works.

Expected: prints 3.

Found while exhausting the #1444 matrix (stage1 of origin/main 1c76062).

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