-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ssa): conditionalise array indexes under IF statements (#1395)
* Condionalize also array access index * Adds regression test * Code review
- Loading branch information
1 parent
4e1560c
commit b857f44
Showing
7 changed files
with
130 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
x = [104, 101, 108, 108, 111] | ||
z = "59" | ||
t = "10" | ||
index = [0,1,2,3,4] | ||
index2 = [0,1,2,3,4] | ||
offset = 1 | ||
sublen = 2 | ||
|
||
|
32 changes: 32 additions & 0 deletions
32
crates/nargo_cli/tests/test_data/array_dynamic/src/main.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
fn main(x: [u32; 5], mut z: u32, t: u32, index: [Field;5], index2: [Field;5], offset: Field, sublen: Field) { | ||
let idx = (z - 5*t - 5) as Field; | ||
//dynamic array test | ||
dyn_array(x, idx, idx - 3); | ||
|
||
//regression for issue 1283 | ||
let mut s = 0; | ||
let x3 = [246,159,32,176,8]; | ||
for i in 0..5 { | ||
s += x3[index[i]]; | ||
} | ||
assert(s!=0); | ||
|
||
if 3 < (sublen as u32) { | ||
assert(index[offset + 3] == index2[3]); | ||
} | ||
} | ||
|
||
fn dyn_array(mut x: [u32; 5], y: Field, z: Field) { | ||
assert(x[y] == 111); | ||
assert(x[z] == 101); | ||
x[z] = 0; | ||
assert(x[y] == 111); | ||
assert(x[1] == 0); | ||
if y as u32 < 10 { | ||
x[y] = x[y] - 2; | ||
} else { | ||
x[y] = 0; | ||
} | ||
assert(x[4] == 109); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters