Skip to content

enum_flags variable assigned from integer literal prints as number instead of flag name #11

@ehartford

Description

@ehartford

Bug

When an `enum_flags` variable is assigned from an integer literal, printing it shows the integer instead of the corresponding flag name(s).

Reproduction

// examples/13/13.3_enum_flags.jai
Direction :: enum_flags {
    NORTH;
    EAST;
    SOUTH;
    WEST;
}

g: Direction = 1;
print("g: %\n", g);

Expected: `g: EAST` (since 1 = bit 0 = EAST)
Actual: `g: 1`

Note: Combined flags using `|` work correctly:

e: Direction = .WEST | .EAST;
print("e: %\n", e);  // correctly prints "EAST | WEST"

Root Cause Analysis

The `emitFormattedEnumFlagsValue` function at line ~14923 of `bytecode_gen.zig` exists and works for compound flag values. The issue is that when a variable is assigned from an integer literal, the format-print path chooses integer formatting instead of enum flags formatting.

At print time, the format system checks the variable's type text to decide how to format it. When `g: Direction = 1`, the type text for `g` should be "Direction" (from the var_decl type annotation), but the print formatting path may not recognize "Direction" as an enum_flags type, or the type text lookup may return "int" (from the integer literal initializer) instead of "Direction".

Files

  • `bootstrap/src/bytecode_gen.zig` (emitFormattedPrint, enum_flags format selection)
  • `bootstrap/src/bytecode_gen.zig` (~line 14923, emitFormattedEnumFlagsValue)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions