radon-project / radon

The Radon Programming Language
https://radon-project.github.io
GNU General Public License v3.0
23 stars 2 forks source link

[BUG]: `nonlocal` raising exception if value is not previously set. #116

Closed Almas-Ali closed 5 months ago

Almas-Ali commented 5 months ago

Describe the bug nonlocal raising exception if value is not previously set.

Screenshots or Code snippets

>>> nonlocal s=3
***
AttributeError: 'NoneType' object has no attribute 'set'
angelcaru commented 5 months ago

Do you think it should throw a Radon exception or just create it as a global?

Almas-Ali commented 5 months ago

This should be like Python for now.

>>> nonlocal sdf
  File "<stdin>", line 1
SyntaxError: nonlocal declaration not allowed at module level
>>> def some():
...     nonlocal jhdsfg
... 
  File "<stdin>", line 2
SyntaxError: no binding for nonlocal 'jhdsfg' found
>>> def some():
...     nonlocal abc = 234
  File "<stdin>", line 2
    nonlocal abc = 234
                 ^
SyntaxError: invalid syntax
>>> abc =1243
>>> def some():
...     nonlocal abc=987
  File "<stdin>", line 2
    nonlocal abc=987
                ^
SyntaxError: invalid syntax
angelcaru commented 5 months ago

But it will be harder to implement. And I like the current system better...

Almas-Ali commented 5 months ago

Not everything I am expecting at this moment. But, I do expect, it should not throw any Python error.

angelcaru commented 5 months ago

Yeah, I am not arguing against that. Will integrate into #115 because it's such a small fix. For now it will throw a Radon error. We can change it later.