Skip to content

support explicit discriminant numbers on tag variants #1393

Closed
@graydon

Description

@graydon

Currently tags always use 0 ... N, where N is the number of tag variants, as the discriminant values.

This makes them useless for modeling C enums, which they are the natural analogue of. We should support a form of variant-declarator that provides a discriminant value, as (say) an uint const expression or something.

Ideal sort of example:

tag color {
red = 0xff;
blue = 0xfe;
}

It'd also be nice to be able to cast back and forth against uint values, and similar "like in C" enum tricks. But one thing at a time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-frontendArea: Compiler frontend (errors, parsing and HIR)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions