Skip to content

Commit

Permalink
fix comptime slicing not preserving comptime mutability
Browse files Browse the repository at this point in the history
 * 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
  • Loading branch information
andrewrk committed Mar 12, 2018
1 parent 49c3922 commit 1bf2810
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ir.cpp
Expand Up @@ -15995,6 +15995,10 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
init_const_ptr_array(ira->codegen, ptr_val, array_val, index, is_const);
if (array_type->id == TypeTableEntryIdArray) {
ptr_val->data.x_ptr.mut = ptr_ptr->value.data.x_ptr.mut;
} else if (is_slice(array_type)) {
ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut;
} else if (array_type->id == TypeTableEntryIdPointer) {
ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut;
}
} else if (ptr_is_undef) {
ptr_val->type = get_pointer_to_type(ira->codegen, parent_ptr->type->data.pointer.child_type,
Expand Down
17 changes: 17 additions & 0 deletions test/cases/eval.zig
Expand Up @@ -469,3 +469,20 @@ fn doesAlotT(comptime T: type, value: usize) T {
test "@setEvalBranchQuota at same scope as generic function call" {
assert(doesAlotT(u32, 2) == 2);
}

test "comptime slice of slice preserves comptime var" {
comptime {
var buff: [10]u8 = undefined;
buff[0..][0..][0] = 1;
assert(buff[0..][0..][0] == 1);
}
}

test "comptime slice of pointer preserves comptime var" {
comptime {
var buff: [10]u8 = undefined;
var a = &buff[0];
a[0..1][0] = 1;
assert(buff[0..][0..][0] == 1);
}
}

0 comments on commit 1bf2810

Please sign in to comment.