erg-lang / erg

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

`fn_name!()` shows closure when Err(()) #358

Closed GreasySlug closed 1 year ago

GreasySlug commented 1 year ago

Describe the behavior?

The macro call (debug_exit_info!()) succeeds however, self.stack_dec(file_name!()) fail to get fn_name!() Not exactly a issue since we are able to get closure, but not the intended one Err will propagate when an error occurs fn_name!() works as intended where the first error occurred

Reproducible code

[1,]

Expected result

[DEBUG] compiler\erg_parser\parse.rs:0676: error caused by: try_reduce_elems at line 675
[DEBUG] compiler\erg_parser\parse.rs:0689: 
・ (5) exit try_reduce_elems, cur: EOF
[DEBUG] compiler\erg_parser\parse.rs:0285: 
・ (4) exit try_reduce_array, cur: EOF 
[DEBUG] compiler\erg_parser\parse.rs:0285: 
 (3) exit try_reduce_bin_lhs, cur: EOF
[DEBUG] compiler\erg_parser\parse.rs:0285: 
 (2) exit try_reduce_chunk, cur: EOF
[DEBUG] compiler\erg_parser\parse.rs:0420: 
 (1) exit try_reduce_module, cur: EOF

Actual result

[DEBUG] compiler\erg_parser\parse.rs:0685: error caused by: try_reduce_elems at line 684
[DEBUG] compiler\erg_parser\parse.rs:0698: 
・ (5) exit try_reduce_elems, cur: EOF
[DEBUG] compiler\erg_parser\parse.rs:0285: 
・ (4) exit {{closure}}, cur: EOF
[DEBUG] compiler\erg_parser\parse.rs:0285: 
 (3) exit {{closure}}, cur: EOF
[DEBUG] compiler\erg_parser\parse.rs:0285: 
 (2) exit {{closure}}, cur: EOF
[DEBUG] compiler\erg_parser\parse.rs:0420: 
 (1) exit try_reduce_module, cur: EOF

Additional context

It is not possible to do so because the following will always call its own method name(stack_dec)

    pub(crate) fn stack_dec(&mut self) {
        self.level -= 1;
        log!(
            c GREEN,
            "\n{} ({}) exit {}, cur: {}",
            "・".repeat((self.level as f32 / 4.0).floor() as usize),
            self.level,
            fn_name!(),
            self.peek().unwrap()
        );
    }

Erg version

Erg 0.6.2-nightly.1

Python version

Python3.11.x

OS

Windows 10

mtshiba commented 1 year ago

solved in https://github.com/erg-lang/erg/commit/6d18fde0b13d3e406c89dd5538c5dddf2b931222.