silver icon indicating copy to clipboard operation
silver copied to clipboard

Duplicate identifier due to quantifier

Open Aurel300 opened this issue 6 months ago • 1 comments

method test() {
    assert forall i: Int :: true
    var i: Int
}

This reports a duplicate identifier. It disappears if I e.g. put the two statements in separate control-flow paths. I understand that if the two lines were in the opposite order, the quantifier would be shadowing the local varaibe i, but in this order it doesn't. (Is this because we hoist variable declarations to the beginning of the block?)

Aurel300 avatar Jun 19 '25 17:06 Aurel300

Right, this happens because the quantifier declares a variable whose name is in use in its parent scope. Our scopes basically mostly ignore where in them a variable is declared (and in the actual AST, that information is not present at all, a scope just knows which variables are declared inside it); if it's declared anywhere in that scope, its name is in use in that scope.

So I'd say this basically works as intended, even though it's not super intuitive.

marcoeilers avatar Jun 24 '25 10:06 marcoeilers