Skip to content
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
18 changes: 16 additions & 2 deletions src/analyze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5458,8 +5458,22 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
case TypeTableEntryIdPointer:
case TypeTableEntryIdFn:
return const_values_equal_ptr(a, b);
case TypeTableEntryIdArray:
zig_panic("TODO");
case TypeTableEntryIdArray: {
assert(a->type->data.array.len == b->type->data.array.len);
assert(a->data.x_array.special != ConstArraySpecialUndef);
assert(b->data.x_array.special != ConstArraySpecialUndef);

size_t len = a->type->data.array.len;
ConstExprValue *a_elems = a->data.x_array.s_none.elements;
ConstExprValue *b_elems = b->data.x_array.s_none.elements;

for (size_t i = 0; i < len; ++i) {
if (!const_values_equal(&a_elems[i], &b_elems[i]))
return false;
}

return true;
}
case TypeTableEntryIdStruct:
for (size_t i = 0; i < a->type->data.structure.src_field_count; i += 1) {
ConstExprValue *field_a = &a->data.x_struct.fields[i];
Expand Down
8 changes: 8 additions & 0 deletions test/cases/array.zig
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,11 @@ fn testImplicitCastSingleItemPtr() void {
slice[0] += 1;
assert(byte == 101);
}

fn testArrayByValAtComptime(b: [2]u8) u8 { return b[0]; }

test "comptime evalutating function that takes array by value" {
const arr = []u8{0,1};
_ = comptime testArrayByValAtComptime(arr);
_ = comptime testArrayByValAtComptime(arr);
}