You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a function, a variable can be declared in a subscope with the same name as another variable in the function, which shadows the previously declared variable. This shouldn't be allowed.
Steps to Reproduce
Copy this contract
pub contract Nodes {
init() {
var node = 1
var i = 1
// are we supposed to be allowed to use a name that we've already used?
while i < 10 {
// which num is used for the assignment?
var node = 3
log(node)
i = i + 1
}
log(node)
}
}
Deploy it and see that there are no errors.
Acceptance Criteria
Checker should report an error that the variable with the same name cannot be declared in a subscope.
The text was updated successfully, but these errors were encountered:
Every function and block ({ ... }) introduces a new scope for declarations
However, you had reported that the variable introduces by a for-in loop was shadowing, which is not correct. Can you please adjust this issue or create a new one for that problem?
joshuahannan
changed the title
BUG: Variable Declarations are shadowed in subscopes
BUG: Variable Declarations are shadowed in for and while-loops
May 28, 2020
Problem
In a function, a variable can be declared in a subscope with the same name as another variable in the function, which shadows the previously declared variable. This shouldn't be allowed.
Steps to Reproduce
Acceptance Criteria
Checker should report an error that the variable with the same name cannot be declared in a subscope.
The text was updated successfully, but these errors were encountered: