Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Freeing variables correctly through visit_Return #2550

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

Closed
wants to merge 1 commit into from

Conversation

anutosh491
Copy link
Collaborator

Fixes #2533

Currently on master as soon as we encountered the return node, we thought it was the end of the program and we could free out everything. But consider the following

from lpython import S
from sympy import Symbol, log

def mmrv(e: S, x: S) -> list[S]:
    print(e)
    print(x)
    if e == x:
        list1: list[S] = [x]
        return list1
    else:
        print(e)
        list2: list[S] = mmrv(x, x)
        return list2

def test_mrv():
    x: S = Symbol("x")
    ans3: list[S] = mmrv(log(x), x)
    ele2: S = ans3[0]
    print(ele2)

test_mrv()

Here we can't free the variable e till the function reaches an end (As it is being used in the 2nd if block). So as shown in the issue this leads to incorrect results

This is now fixed and we get the correct output

log(x)
x
log(x)
x
x
x

@anutosh491
Copy link
Collaborator Author

Closing as #2569 is a better approach to address this issue

@anutosh491 anutosh491 closed this Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issues while trying to print symbolic expressions
1 participant