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

[Docs]: Implicitly declared local variables (in def functions) may not be function-scoped #1574

Closed
duckki opened this issue Dec 29, 2023 · 2 comments
Labels
bug Something isn't working mojo-docs mojo-repo Tag all issues with this label

Comments

@duckki
Copy link

duckki commented Dec 29, 2023

Bug description

Implicitly declared local variables are supposed to have the function-level scope (as stated in the doc). But, it appears to be restricted to the scope they were assigned.

Steps to reproduce

def example( nondet ):
    # Exepcted that `v` is declared function-wide.
    # Thus, the implicit declaration of `var v` should've been hoisted to the top of the function.
    if nondet:
        v = 1 # assignment here, implicitly declaring a local variable `v`
    else:
        v = 2
    print( v ) # error: "use of unknown declaration 'v'"

System information

- macOS Sonoma
- mojo 0.6.1 (876ded2e)
- modular 0.3.0 (8afa5600)
@duckki duckki added bug Something isn't working mojo Issues that are related to mojo labels Dec 29, 2023
@duckki
Copy link
Author

duckki commented Dec 29, 2023

It seems related to the intentional scoping deviation from Python mentioned in the roadmap.

for i in range(3): pass
print(i) # error in Mojo

@ematejska
Copy link
Collaborator

Yes, exactly but the documentation could be improved here.

@ematejska ematejska added the documentation Improvements or additions to documentation label Jan 3, 2024
@ematejska ematejska changed the title [BUG]: Implicitly declared local variables (in def functions) may not be function-scoped [Docs]: Implicitly declared local variables (in def functions) may not be function-scoped Jan 3, 2024
@linear linear bot added mojo-repo Tag all issues with this label test-sync-delete after and removed mojo Issues that are related to mojo mojo-repo Tag all issues with this label documentation Improvements or additions to documentation test-sync-delete after labels Apr 29, 2024
@scottamain scottamain added the docs label May 9, 2024 — with Linear
@linear linear bot added the mojo-docs label May 13, 2024
@linear linear bot closed this as completed May 16, 2024
@scottamain scottamain removed the docs label Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mojo-docs mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

3 participants