erg-lang / erg

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

Cannot declare high-order func/procs #303

Closed GreasySlug closed 1 year ago

GreasySlug commented 1 year ago

Describe the bug?

Cannot define or call higher-order functions that allow functions to be defined for arguments and return values

Reproducible code

add x = y -> x + y
assert add(10)(100) == 110

Expected result

No error

Actual result

thread '' panicked at 'called Option::unwrap() on a None value', compiler\erg_compiler\ty\codeobj.rs:545:54 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace thread 'main' panicked at 'called Result::unwrap() on an Err value: Any { .. }', C:\Users\user\Desktop\erg\compiler\erg_common\spawn.rs:18:22 [DEBUG] compiler\erg_compiler\compile.rs:0224: error: process didn't exit successfully: target\debug\erg.exe .\examples\high.er (exit code: 101)

Additional context

Perhaps this is a python 3.10.8 specific issue as well. If REPL is invoked in debug mode and declarations are made, errors will occur in the declarations to begin with.

>>> a x = y -> x + y

--- omit ---

[DEBUG] compiler\erg_compiler\codegen.rs:3091: the code-generating process has completed.
thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', compiler\erg_compiler\ty\codeobj.rs:545:54
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[DEBUG] compiler\erg_compiler\compile.rs:0238: The REPL server is closed.
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Any { .. }', C:\Users\user\Desktop\erg\compiler\erg_common\spawn.rs:18:22
error: process didn't exit successfully: `target\debug\erg.exe` (exit code: 101)

Erg version

Erg 0.6.0-beta.3

Python version

python3.10.8

OS

Windows 10