Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Translator.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3105,7 +3105,7 @@ fn transArrayAccess(t: *Translator, scope: *Scope, array_access: Node.ArrayAcces
const index = index: {
const index = try t.transExpr(scope, array_access.index, .used);
const index_qt = array_access.index.qt(t.tree);
const maybe_bigger_than_usize = switch (index_qt.base(t.comp).type) {
const maybe_bigger_than_usize = type: switch (index_qt.base(t.comp).type) {
.bool => {
break :index try ZigTag.int_from_bool.create(t.arena, index);
},
Expand All @@ -3114,6 +3114,7 @@ fn transArrayAccess(t: *Translator, scope: *Scope, array_access: Node.ArrayAcces
else => false,
},
.bit_int => |bit_int| bit_int.bits > t.comp.target.ptrBitWidth(),
.@"enum" => |e| if (e.tag) |tag| continue :type tag.base(t.comp).type else false,
else => unreachable,
};

Expand Down
29 changes: 29 additions & 0 deletions test/cases/translate/array_access_with_enum.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
typedef enum {
one = 1,
two = 2,
} EnumValues;

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

// translate
// target=native-linux
//
// pub const one: c_int = 1;
// pub const two: c_int = 2;
// pub const EnumValues = c_uint;
// pub fn dynamic_array_access(arg_idx: EnumValues) callconv(.c) c_int {
// var idx = arg_idx;
// _ = &idx;
// const static_local_values = struct {
// const values: [3]c_int = [3]c_int{
// 0,
// 1,
// 2,
// };
// };
// _ = &static_local_values;
// return static_local_values.values[idx -% @as(EnumValues, 1)];
// }