aptos-core
aptos-core copied to clipboard
[Bug] `vector::for_each_mut` is not working when dereference the value.
🐛 Bug
vector::for_each_mut
is not working when dereference the value. More detail below.
To reproduce
fun main() {
let amounts = vector[1u64, 2u64];
vector::for_each_mut(&mut amounts, |amount| {
// *amount = 1000000; // this works. amounts == vector[1000000u64, 1000000u64]
// test_mul(amount, 1000000); // this also works. amounts == vector[1000000u64, 2000000u64]
*amount = *amount * 1000000; // got error `Invalid mutation. Expected a mutable reference`
});
}
inline fun test_mul(a: &mut u64, b: u64) {
*a = *a * b;
}
Expected Behavior
I think it is some kind of compiler bug. The third one is same with using test_mul
function logically.
System information
Please complete the following information:
- Aptos Core Version: cli version 3.0.0
- Rust Version: rustc 1.77.2 (25ef9e3d8 2024-04-09)
- Computer OS: Mac OS 14.2.1(23C71)