move
move copied to clipboard
[Bug] Unused variable error happens when it used
🐛 Bug
I'm trying to compile module contains while loop and variable defined before loop. Each iteration i change variable value. Yet i'm getting error and it seems a compiler bug.
To reproduce
module 0x1::Bug {
public fun loop_over() {
let i = 0;
let something = 604800;
let my_counter = 0;
while (i < 100) {
my_counter = something * i;
if (my_counter > 100) {
// do something
};
i = i + 1;
}
}
}
I got an error during compilation:
warning[W09003]: unused assignment
┌─ ./sources/Bug.move:5:13
│
5 │ let my_counter = 0;
│ ^^^^^^^^^^ Unused assignment or binding for local 'my_counter'. Consider removing, replacing with '_', or prefixing with '_' (e.g., '_my_counter')
Expected Behavior
I understand i can do let my_counter = something * i;
in the start of each loop iteration instead of define counter before loop, yet i think my initial example should compile or show some explained error/warning.
Additional Context
I'm using Aptos CLI 0.1.2.
A bad error message, but it is finding something! The initial value is not used, so you could have let my_counter;
Hi @tnowacki ,
Yeah, right, but still i think error message should be fixed, the rustc showing me something like:
warning: value assigned to `my_counter` is never read
IMHO, much more clear