Skip to content

Compiler panics on a discriminant at the repr maximum (i32 auto-increment overflow) and on u64 discriminants above i64::MAX #1452

Closed

Description

@ehartford

Spec: §4.4a Discriminant Enums (representation types i8 … u64; "each variant is assigned an explicit integer value with = N").

The compiler aborts (exit 134) on two valid declarations:

enum K: i32:
    A = 1
    B = 2147483647

fn main:
    print(K.B as i32)
panic: integer overflow: i32 addition out of range

The parser auto-increments after every variant (current_disc = current_disc + 1), including the last one, so a last variant at the repr's maximum overflows the counter even though no variant needs the next value.

enum K: u64:
    A = 1
    B = 18446744073709551615

fn main:
    print(K.B as u64)
panic: integer overflow: i64 multiplication out of range

A u64 discriminant above i64::MAX overflows the i64 literal accumulator.

Expected: both compile; the first prints 2147483647, the second 18446744073709551615. An auto-incremented variant that would need a value past the repr's range is a diagnostic naming the variant, not a panic.

Found while exhausting the #1444 matrix (installed nightly-20260922-local-1-8c859a7d0559).

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