Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Variable Declarations are shadowed in for and while-loops #72

Closed
joshuahannan opened this issue May 6, 2020 · 1 comment · Fixed by #149
Closed

BUG: Variable Declarations are shadowed in for and while-loops #72

joshuahannan opened this issue May 6, 2020 · 1 comment · Fixed by #149
Assignees
Labels
Bug Something isn't working Good First Issue Good for newcomers

Comments

@joshuahannan
Copy link
Member

joshuahannan commented May 6, 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

  1. 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)
    }
}
  1. 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.

@joshuahannan joshuahannan added the Bug Something isn't working label May 6, 2020
@benjaminkvm benjaminkvm self-assigned this May 6, 2020
@turbolent turbolent added the Good First Issue Good for newcomers label May 7, 2020
@turbolent
Copy link
Member

turbolent commented May 28, 2020

This is working as expected: From https://github.com/onflow/cadence/blob/master/docs/language.md#scope:

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 joshuahannan changed the title BUG: Variable Declarations are shadowed in subscopes BUG: Variable Declarations are shadowed in for and while-loops May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Good First Issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants