mirror of
https://github.com/ziglang/zig.git
synced 2026-01-30 19:23:37 +00:00
Merge pull request #1167 from ziglang/comptime-array-by-value
Implement const_values_equal for arrays
This commit is contained in:
commit
42033ea3ca
@ -5471,8 +5471,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];
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user