erg-lang / erg

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

parser causes panic when in debug mode #400

Closed GreasySlug closed 1 year ago

GreasySlug commented 1 year ago

Describe the bug?

Parsing EOF with Parser may consume EOF in rare cases This causes a panic because it cannot get the token with debug_exit_info!

Reproducible code

cargo dprs

a = (
    1
                let rparen = self.lpop(); <- consume EOF
                if let Expr::Tuple(Tuple::Normal(tup)) = &mut expr {
                    tup.elems.paren = Some((lparen, rparen));
                }

Expected result

Syntax error

Actual result

panic

Additional context

No response

Erg version

0.6.4

Python version

Python3.11

OS

Windows 10

mtshiba commented 1 year ago

I fixed this issue and introduced a useful macro expect_pop!.

This macro expects a specific token at the current position and returns an error if not.