noname icon indicating copy to clipboard operation
noname copied to clipboard

Can't use same for loop var

Open katat opened this issue 7 months ago • 1 comments

given:

fn main(pub public_input: Field, private_input: [Field; 3]) {
    let mut sum = 0;

    for ii in 0..3 {
        sum = sum + private_input[ii];
    
    }
    for ii in 0..3 {
        sum = sum + private_input[ii];
    }

    assert_eq(sum, public_input);
}

it throws error at the second for loop:

   ╭─[for_loop:7:1]
 7 │     }
 8 │     for ii in 0..3 {
   ·         ─┬
   ·          ╰── here
 9 │         sum = sum + private_input[ii];
   ╰────
  help: the variable `ii` is declared twice

The cause is the TypedFnEnv use var name as key to store vars, but it doesn't remove the vars that are out of scope.

katat avatar Jul 21 '24 09:07 katat