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

Redefining nested function from other function overrides original nested function #861

Closed
BPYap opened this Issue Jul 2, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@BPYap
Contributor

BPYap commented Jul 2, 2018

Consider the following codes saved in Test.py:

def func():
    def nested_func():
        print("Hello World from func")
    
    nested_func()

def func2():
    def nested_func():
        print("Hello World from func2")

    nested_func()

func()
func2()

Running the codes in voc results in following outputs:

Hello World from func2
Hello World from func2

However, the intended outputs from Python 3.6 are:

Hello World from func
Hello World from func2

Upon investigation, nested_function is overwritten during transpilation as voc generates new class file for nested function:

Compiling Test.py ...
Writing .\python\Test.class ...
Writing .\python\Test\nested_func.class ...
Writing .\python\Test\nested_func.class ...

The last write overwrites the first nested function.

One potential way to solve it would be generating class files for each nested function marked with enclosing function's name and instruct voc to look for the correct class file when invoking nested function.

BPYap added a commit to BPYap/voc that referenced this issue Jul 2, 2018

freakboy3742 added a commit that referenced this issue Jul 6, 2018

freakboy3742 added a commit that referenced this issue Jul 13, 2018

Merge pull request #868 from BPYap/fix-redefining-nested-class
Fixed #861 Redefining nested function from other function overrides original nested function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment