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

Crash when importing invalid module on REPL #179

Closed GreasySlug closed 2 years ago

GreasySlug commented 2 years ago

Describe the bug

Related #176

Invalid import causes multiple error messages and then crashes on any input.

Reproducible code

>>> import "a"
Traceback (most recent call last):
  File "<string>", line 28, in <module>
  File "<string>", line 1, in <module>
  File "<stdin>", line -1, in <module>
ModuleNotFoundError: No module named 'a'

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:77:49
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Any { .. }', src\main.rs:63:22    
error: process didn't exit successfully: `target\debug\erg.exe` (exit code: 101)

Expected behavior

Error message and don't crash

Additional context

The following code is crashing at stream.write_all("exit".as_bytes()).unwrap();

If it fails to read, it seems to fail to write as well

https://github.com/erg-lang/erg/blob/f6e1a7b11783d7f4c78f4e1e1ba6cda048747fc8/src/dummy.rs#L75-L78

mtshiba commented 2 years ago

To our surprise, the crash was caused by a single line of error.

before:

https://github.com/erg-lang/erg/blob/01451ee8217d8e4ce3cb243a58be9d8da8eb4a7a/compiler/erg_compiler/codegen.rs#L591

after:

https://github.com/erg-lang/erg/blob/f9e35aab2d1155f1397fd1c62d0835bdaaded449/compiler/erg_compiler/codegen.rs#L596

Python was crashing because the stack size was incorrectly specified. If we get no response from Python, we should suspect a bug in code generation.