Skip to content

Commit

Permalink
Fix array_snapshot_pop_back and add test. (#1080)
Browse files Browse the repository at this point in the history
  • Loading branch information
azteca1998 authored Feb 4, 2025
1 parent 03273cb commit 1971591
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions src/libfuncs/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,10 +1160,13 @@ fn build_pop<'ctx, 'this, const CONSUME: bool, const REVERSE: bool>(
IntegerType::new(context, 8).into(),
)?;

let data_ptr = if REVERSE {
array_ptr
} else {
let offset = block.addi(array_start, extract_len_value, location)?;
let data_ptr = {
let offset = if REVERSE {
array_start
} else {
block.addi(array_start, extract_len_value, location)?
};

let offset = block.append_op_result(arith::extui(
offset,
IntegerType::new(context, 64).into(),
Expand Down Expand Up @@ -3095,4 +3098,34 @@ mod test {
),
);
}

#[test]
fn array_snapshot_pop_back_clone_offset() {
let program = load_cairo! {
fn run_test() -> Span<felt252> {
let data = array![7, 3, 4, 193827];
let mut data = data.span();

assert(*data.pop_front().unwrap() == 7, 0);
let data2 = data.clone();

assert(*data.pop_back().unwrap() == 193827, 1);

drop(data2);
data
}
};
let result = run_program(&program, "run_test", &[]).return_value;

assert_eq!(
result,
jit_enum!(
0,
jit_struct!(jit_struct!(Value::Array(vec![
Value::Felt252(3.into()),
Value::Felt252(4.into()),
])))
),
);
}
}

0 comments on commit 1971591

Please sign in to comment.