authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-03-12 01:21:10-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-03-12 01:21:10-04:00
log1bf2810f338a7bf83455266ef66a535bdc1d4f83
treec7abc8f4a0a6b0fed5621051ce2a02d3ec9a0835
parent49c3922037ef0b913466e707d85a4e085f6e9716

fix comptime slicing not preserving comptime mutability

* fix comptime slice of slice not preserving mutatibility of the comptime data * fix comptime slice of pointer not preserving mutability of the comptime data closes #826

2 files changed, 21 insertions(+), 0 deletions(-)

src/ir.cpp+4
......@@ -15995,6 +15995,10 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
1599515995 init_const_ptr_array(ira->codegen, ptr_val, array_val, index, is_const);
1599615996 if (array_type->id == TypeTableEntryIdArray) {
1599715997 ptr_val->data.x_ptr.mut = ptr_ptr->value.data.x_ptr.mut;
15998 } else if (is_slice(array_type)) {
15999 ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut;
16000 } else if (array_type->id == TypeTableEntryIdPointer) {
16001 ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut;
1599816002 }
1599916003 } else if (ptr_is_undef) {
1600016004 ptr_val->type = get_pointer_to_type(ira->codegen, parent_ptr->type->data.pointer.child_type,
test/cases/eval.zig+17
......@@ -469,3 +469,20 @@ fn doesAlotT(comptime T: type, value: usize) T {
469469test "@setEvalBranchQuota at same scope as generic function call" {
470470 assert(doesAlotT(u32, 2) == 2);
471471}
472
473test "comptime slice of slice preserves comptime var" {
474 comptime {
475 var buff: [10]u8 = undefined;
476 buff[0..][0..][0] = 1;
477 assert(buff[0..][0..][0] == 1);
478 }
479}
480
481test "comptime slice of pointer preserves comptime var" {
482 comptime {
483 var buff: [10]u8 = undefined;
484 var a = &buff[0];
485 a[0..1][0] = 1;
486 assert(buff[0..][0..][0] == 1);
487 }
488}