Skip to content

Commit bfb34a6

Browse files
authored
Fix array indexing bug (#29243)
Allow indexing of arrays with non strictly decimal literals which previously failed at codegen because it wasn't handled properly. Fixes #29229
1 parent fdcd5dc commit bfb34a6

File tree

7 files changed

+31
-1
lines changed

7 files changed

+31
-1
lines changed

crates/passes/src/code_generation/expression.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ impl CodeGeneratingVisitor<'_> {
403403
Expression::Literal(Literal {
404404
variant: LiteralVariant::Integer(_, s) | LiteralVariant::Unsuffixed(s),
405405
..
406-
}) => AleoExpr::U32(s.parse().unwrap()),
406+
}) => AleoExpr::U32(u32::from_str_by_radix(&s.replace('_', "")).unwrap()),
407407
_ => panic!("Array indices must be integer literals"),
408408
};
409409

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
program test.aleo;
2+
3+
function foo:
4+
input r0 as [boolean; 8u32].private;
5+
output r0[1u32] as boolean.private;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
program test.aleo;
2+
3+
function foo:
4+
input r0 as [boolean; 256u32].private;
5+
output r0[10u32] as boolean.private;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
program test.aleo;
2+
3+
function main:
4+
output 6u32 as u32.private;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
program test.aleo {
2+
fn foo(a: [bool; 8]) -> bool {
3+
return a[0x1u32];
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
program test.aleo {
2+
fn foo(a: [bool; 256]) -> bool {
3+
return a[1_0u32];
4+
}
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
program test.aleo {
2+
fn main() -> u32 {
3+
let arr = [1u32, 2u32, 3u32];
4+
return arr[0x0] + arr[0x1] + arr[0x2];
5+
}
6+
}

0 commit comments

Comments
 (0)