lpython icon indicating copy to clipboard operation
lpython copied to clipboard

Program passes lpython but not CPython

Open rebcabin opened this issue 1 year ago • 5 comments

from lpython import CPtr

A : CPtr

def foo(a : CPtr) -> None:
    pass

foo(A)
(lp) ┌─(~/Documents/GitHub/lpython/integration_tests)───(brian@MacBook-Pro:s001)─┐
└─(19:55:25 on vector-backend ✹ ✭)──> lpython ../ISSUES/UNHANDLED-EXCEPTIONS/Issue2487.py    
(lp) ┌─(~/Documents/GitHub/lpython/integration_tests)───(brian@MacBook-Pro:s001)─┐
└─(19:55:35 on vector-backend ✹ ✭)──> PYTHONPATH=".:../src/runtime/lpython:.." LPYTHON_PY_MOD_NAME="" LPYTHON_PY_MOD_PATH="_lpython-tmp-test-cpython" python ../ISSUES/UNHANDLED-EXCEPTIONS/Issue2487.py
Traceback (most recent call last):
  File "/Users/brian/Dropbox/Mac/Documents/GitHub/lpython/integration_tests/../ISSUES/UNHANDLED-EXCEPTIONS/Issue2487.py", line 8, in <module>
    foo(A)
NameError: name 'A' is not defined

rebcabin avatar Feb 06 '24 03:02 rebcabin

@Shaikh-Ubaid , this error does not occur on the latest main. Could you please verify it?

kmr-srbh avatar Apr 23 '24 09:04 kmr-srbh

@kmr-srbh There would be no error with lpython, but there will be error with cpython, I think.

ubaidsk avatar Apr 23 '24 09:04 ubaidsk

Oh! I am sorry I overlooked this. I am trying to figure out the cause of the issue. The bug exists for the other types as well. Thank you @Shaikh-Ubaid!

kmr-srbh avatar Apr 23 '24 09:04 kmr-srbh

The bug exists for the other types as well.

Yes, it would.

In python, you need to assign to a variable in order for the variable to be declared. In the above example, we do not have an assignment, but we just have a mention of the variable and its type.

Specifying a variable with its type leads to variable declaration in lpython, but I think it is just ignored by cpython.

ubaidsk avatar Apr 23 '24 09:04 ubaidsk

Exactly @Shaikh-Ubaid ! This is something where we differ from being a subset of CPython in a significant way.

kmr-srbh avatar Apr 23 '24 09:04 kmr-srbh