go-python / gpython

gpython is a python interpreter written in go "batteries not included"
BSD 3-Clause "New" or "Revised" License
870 stars 95 forks source link

Double underlines("_") for nonlocal variable names crash gpython #200

Closed xiaxinmeng closed 1 year ago

xiaxinmeng commented 1 year ago

The following code take two underlines("_") and x as the name of a nonlocal variable x. gpython crashes with a segmentation fault.

Crashing Message: segmentation fault.

class A:
    def f(self):
        nonlocal __x

environment: gpython 0.1.0 on Ubuntu 18.04, and gpython main(https://github.com/go-python/gpython/commit/6f8e06a4660709ab44398d8b1a18738aa407b1c3 on Oct 5)

ncw commented 1 year ago

This works for me

$ cat > issue-200.py
class A:
    def f(self):
        nonlocal __x

$ gpython issue-200.py 
2022/12/05 08:53:43 Can't compile "issue-200.py": 
  File "issue-200.py", line 3, offset 8

SyntaxError: "no binding for nonlocal '__x' found"