erg-lang / erg

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

Multiple assignments causes panic #205

Closed GreasySlug closed 1 year ago

GreasySlug commented 2 years ago

Describe the bug?

Although multiple substitution is not allowed in erg. If it did, it would cause a panic, not a syntax error.

Reproducible code

cargo run

>>> a = a = 1

Expected result

>>> a = b = 1
Error[#1925]: File <stdin>, line 1
1│ a = b = 1
       ^
SyntaxError: invalid syntax

Actual result

>>> a = b = 1
current block: CompilerUnit{
id: 1
code:
Disassembly of <code object <module> at 0x1f682d46118, 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:        3
Flags:             NoFree
Constants:
   0: 0
   1: ["namedtuple"]
   2: ["path"]
   3: "C:\Users\username/.erg/std"
   4: ["in_operator"]
   5: 1
Names:
   0: collections
   1: namedtuple
   2: ::#NamedTuple
   3: sys
   4: path
   5: ::#path
   6: append
   7: _erg_std_prelude
   8: in_operator
   9: ::#in_operator
   10: print
   11: ::b
   12: ::a
lnotab: []
1:
              0 LOAD_CONST               0 (0)
              2 LOAD_CONST               1 (["namedtuple"])
              4 IMPORT_NAME              0 (collections)
              6 IMPORT_FROM              1 (namedtuple)
              8 STORE_GLOBAL             2 (::#NamedTuple)
             10 POP_TOP
             12 LOAD_CONST               0 (0)
             14 LOAD_CONST               2 (["path"])
             16 IMPORT_NAME              3 (sys)
             18 IMPORT_FROM              4 (path)
             20 STORE_GLOBAL             5 (::#path)
             22 POP_TOP
             24 LOAD_NAME                5 (::#path)
             26 LOAD_METHOD              6 (append)
             28 LOAD_CONST               3 ("C:\Users\username/.erg/std")
             30 CALL_METHOD              1
             32 POP_TOP
             34 LOAD_CONST               0 (0)
             36 LOAD_CONST               4 (["in_operator"])
             38 IMPORT_NAME              7 (_erg_std_prelude)
             40 IMPORT_FROM              8 (in_operator)
             42 STORE_GLOBAL             9 (::#in_operator)
             44 POP_TOP
             46 LOAD_NAME                10 (print)
             48 LOAD_CONST               5 (1)
             50 STORE_NAME               11 (::b)
             52 STORE_NAME               12 (::a)

}

Additional context

No response

Erg version

0.5.9-nightly.0

Python version

Python 3.10.6

os

Windows 10