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

Variable scope issue #39

Closed
YohanFinet opened this issue Aug 13, 2021 · 4 comments
Closed

Variable scope issue #39

YohanFinet opened this issue Aug 13, 2021 · 4 comments
Assignees
Labels
bug Something isn't working solved This issue is solved
Milestone

Comments

@YohanFinet
Copy link
Collaborator

YohanFinet commented Aug 13, 2021

When a local variable has the same name as a global variable, flyable thinks we are talking about the global variable.

example 1:

x = "global "

def foo():
    x = x * 2
    print(x)

foo()
print(x)

cpython: error
flyable: prints global global

example 2:

x = "global "

def foo():
    x = "hello"
    print(x)

foo()
print(x)

cpython: prints hello global
flyable: prints hello hello

@YohanFinet YohanFinet added the bug Something isn't working label Aug 13, 2021
@YohanFinet
Copy link
Collaborator Author

There's an issue with the scope of nested functions that might be related.

example:

def outer():
    x = "hello"

    def inner():
        x = "world"
        print("inner:" + x)

    inner()
    print("outer:" + x)

def foo():
    inner()

outer()
foo()

the above code prints:
inner:world
outer:hello
inner:world

But it should raise an error since foo() shouldn't be able to call inner().

@ALavallee ALavallee self-assigned this Aug 14, 2021
@ALavallee ALavallee added this to the Beta milestone Feb 4, 2022
@ALavallee
Copy link
Contributor

@MoSk3 Is this one good to close?

@MoSk3
Copy link
Collaborator

MoSk3 commented Feb 4, 2022

Not fully, still working on the error raising

@ALavallee
Copy link
Contributor

Cpython opcodes take cares of that. We will just need to lookup provided in the Function Frame.

@ALavallee ALavallee added the solved This issue is solved label Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working solved This issue is solved
Projects
None yet
Development

No branches or pull requests

3 participants