Skip to content
This repository has been archived by the owner. It is now read-only.

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

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

Comments

@BPYap
Copy link
Contributor

@BPYap 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
Added test case for issue #861
freakboy3742 added a commit that referenced this issue Jul 13, 2018
Fixed #861 Redefining nested function from other function overrides original nested function
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant