Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

Array access via Enum type fails #227

Description

@steeve

Hey, thank you for this great project!

Here is a quick reproducer:

typedef enum {
    one = 1,
    two = 2,
    three = 3,
    four = 4,
} EnumValues;

static inline int dynamic_array_access(EnumValues idx) {
  static const int values[] = {0, 1, 2, 3, 4};
  return values[idx - 1];
}

It will reach the following unreachable at

translate-c/src/Translator.zig

Lines 3108 to 3118 in 0a146cc

const maybe_bigger_than_usize = switch (index_qt.base(t.comp).type) {
.bool => {
break :index try ZigTag.int_from_bool.create(t.arena, index);
},
.int => |int| switch (int) {
.long_long, .ulong_long, .int128, .uint128 => true,
else => false,
},
.bit_int => |bit_int| bit_int.bits > t.comp.target.ptrBitWidth(),
else => unreachable,
};

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions