| author | |
| committer | |
| log | 1bf2810f338a7bf83455266ef66a535bdc1d4f83 |
| tree | c7abc8f4a0a6b0fed5621051ce2a02d3ec9a0835 |
| parent | 49c3922037ef0b913466e707d85a4e085f6e9716 |
* 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 #8262 files changed, 21 insertions(+), 0 deletions(-)
src/ir.cpp+4| ... | ... | @@ -15995,6 +15995,10 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 15995 | 15995 | init_const_ptr_array(ira->codegen, ptr_val, array_val, index, is_const); |
| 15996 | 15996 | if (array_type->id == TypeTableEntryIdArray) { |
| 15997 | 15997 | 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; | |
| 15998 | 16002 | } |
| 15999 | 16003 | } else if (ptr_is_undef) { |
| 16000 | 16004 | 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 { |
| 469 | 469 | test "@setEvalBranchQuota at same scope as generic function call" { |
| 470 | 470 | assert(doesAlotT(u32, 2) == 2); |
| 471 | 471 | } |
| 472 | ||
| 473 | test "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 | ||
| 481 | test "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 | } |