erg-lang / erg

A statically typed language compatible with Python
http://erg-lang.org
Apache License 2.0
2.7k stars 55 forks source link

Mutable variable with pre-operator causes panic #408

Closed GreasySlug closed 1 year ago

GreasySlug commented 1 year ago

Describe the bug?

Declaring a mutable variable and attaching a pre-minus or pre-plus to it causes panic

Reproducible code

a = !1
+a
>>> a = !1

>>> +a

Expected result

1

Actual result

Disassembly of <code object <module> at 0x6eb1cf6258, file "<stdin>", 
line 1>:
Name:              <module>
FileName:          <stdin>
Argument count:    0
Positional-only arguments: 0
Kw-only arguments: 0
Number of locals:  0
Stack size:        2
Flags:
Constants:
   0: None
Names:
   0: ::a
lnotab: []
1:
              0 RESUME
              2 LOAD_NAME                 0 (::a)
              4 UNARY_POSITIVE
              6 PRINT_EXPR
              8 LOAD_CONST                0 (None)
             10 RETURN_VALUE

[DEBUG] crates\erg_compiler\compile.rs:0240: the compiling process has completed
Traceback (most recent call last):
  File "<string>", line 30, in <module>
  File "<string>", line 1, in <module>
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\importlib\__init__.py", line 169, in reload
    _bootstrap._exec(spec, module)
  File "<frozen importlib._bootstrap>", line 621, in _exec
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<stdin>", line -1, in <module>
TypeError: bad operand type for unary +: 'NatMut'

During handling of the above exception, another exception occurred:   

Traceback (most recent call last):
  File "<string>", line 36, in <module>
NameError: name 'e' is not defined

Additional context

No response

Erg version

Erg 0.6.7-nightly.2

Python version

Python3.11

OS

Windows 10