lcompilers / lpython

Python compiler
https://lpython.org/
Other
1.37k stars 156 forks source link

Updated test_gruntz.py #2656

Closed anutosh491 closed 2 months ago

anutosh491 commented 2 months ago

This PR introduces some changes and a case in test gruntz.py The changes introduced are related to freeing out variables.

anutosh491 commented 2 months ago

So something that doesn't work perfectly as of now is this

from lpython import S
from sympy import Symbol, E

def mmrv(e: S) -> S:
    if False:
        print(E)
    else:
        return e

def test_mrv():
    x: S = Symbol("x")
    ans: S = mmrv(x)
    print(ans)

test_mrv()

But something that does work perfectly ( a very fair workaround ) is this

from lpython import S
from sympy import Symbol, E

def mmrv(e: S) -> S:
    if False:
        var: S = E
        print(var)
    else:
        return e

def test_mrv():
    x: S = Symbol("x")
    ans: S = mmrv(x)
    print(ans)

test_mrv()

Hence the PR updates test_gruntz.py and we use assignment wherever we see vulnerabilites related to freeing out basic variables.

anutosh491 commented 2 months ago

The PR also introduces a case where the base of a Pow expression might be E (basically exponential cases which is just a Pow case with base E as per symengine)