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

In REPL, panic when accessing invalid variables #283

Closed GreasySlug closed 1 year ago

GreasySlug commented 1 year ago

Describe the bug?

Causes an error in the block of lambda Attempting to use the name of the variable will cause an error and then panic.

Reproducible code

a = () -> print! "hi"

by the way, this following code is correct?

a = () -> print!

I had thought that you couldn't even declare a procedure with side-effects within lambda.

Expected result

Just error not panic a is not defined

Actual result

>>> a
Traceback (most recent call last):
  File "<string>", line 28, in <module>
  File "<string>", line 1, in <module>
  File "<stdin>", line -1, in <module>
NameError: name '::a' is not defined

During handling of the above exception, another exception occurred:

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

>>>
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 10053, 
kind: ConnectionAborted, message: "確立された接続がホスト コンピューターのソウトウェアによって 
中止されました。" }', src\dummy.rs:94:49
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 10053, 
kind: ConnectionAborted, message: "確立された接続がホスト コンピューターのソウトウェアによって 
中止されました。" }', src\dummy.rs:94:49
stack backtrace:

Additional context

No response

Erg version

Erg 0.6.0-beta.1

Python version

python3.10.8

OS

Windows 10

mtshiba commented 1 year ago

() -> print! is allowed, since it has no side effect. However, the return value of the call must be bound with !.

a = () -> print!
b = a() # ERR: cannot assign a procedure to a normal variable