Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion compiler/noirc_evaluator/src/ssa/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,25 @@ impl<'ssa, W: Write> Interpreter<'ssa, W> {
let element = elements.get(index as usize).ok_or_else(|| {
InterpreterError::IndexOutOfBounds { index, length: elements.len() as u32 }
})?;
element.clone()

// Either return a fresh nested array (in constrained context) or just clone the element.
if !self.in_unconstrained_context() {
if let Some(array) = element.as_array_or_slice() {
// In the ACIR runtime we expect fresh arrays when accessing a nested array.
// If we do not clone the elements here a mutable array set afterwards could mutate
// not just this returned array but the array we are fetching from in this array get.
Value::ArrayOrSlice(ArrayValue {
elements: Shared::new(array.elements.borrow().to_vec()),
rc: array.rc,
element_types: array.element_types,
is_slice: array.is_slice,
})
} else {
element.clone()
}
} else {
element.clone()
}
};
self.define(result, element)?;
Ok(())
Expand Down
Loading