buzz-language / buzz

👨‍🚀 buzz, A small/lightweight statically typed scripting language
https://buzz-lang.dev
MIT License
1.15k stars 31 forks source link

Buzz crashes trying to parse unusual file #266

Closed yohannd1 closed 1 month ago

yohannd1 commented 4 months ago

Hello! This is a really interesting project! I love the concept of a strongly typed scripting language and so far it seems the startup time barely even suffers from it (I got jumpscared by the SDL example's speed).

Anyway - I accidentally came across a rather... unusual bug. Buzz crashes if it tries to parse a file with just an a inside it (the ~/test.buzz in question on the error log below).

~/pj/clone/buzz exit:1> echo "a" > ~/test.buzz && zig build -Doptimize=Debug run -- ~/test.buzz
thread 83936 panic: integer overflow
/home/yohanan/pj/clone/buzz/src/Parser.zig:411:86: 0x10c2d10 in parse (buzz)
    self.reporter.reportErrorAt(error_type, self.ast.tokens.get(self.current_token.? - 1), message);
                                                                                     ^
/home/yohanan/pj/clone/buzz/src/main.zig:87:25: 0x10cde48 in runFile (buzz)
    if (try parser.parse(source, file_name)) |ast| {
                        ^
/home/yohanan/pj/clone/buzz/src/main.zig:268:16: 0x10cfd53 in main (buzz)
        runFile(
               ^
/home/yohanan/.cache/zigup/0.12.0-dev.2541+894493549/files/lib/std/start.zig:585:37: 0x10d0aa6 in main (buzz)
            const result = root.main() catch |err| {
                                    ^
???:?:?: 0x7fac38645ccf in ??? (libc.so.6)
Unwind information for `libc.so.6:0x7fac38645ccf` was not available, trace may be incomplete

run
└─ run buzz failure
error: the following command terminated unexpectedly:
/home/yohanan/pj/clone/buzz/zig-out/bin/buzz /home/yohanan/test.buzz
Build Summary: 50/52 steps succeeded; 1 failed (disable with --summary none)
run transitive failure
└─ run buzz failure
error: the following build command failed with exit code 1:
/home/yohanan/pj/clone/buzz/zig-cache/o/479c400045a5007e25a57a54a84c8cf2/build /home/yohanan/.cache/zigup/0.12.0-dev.2541+894493549/files/zig /home/yohanan/pj/clone/buzz /home/yohanan/pj/clone/buzz/zig-cache /home/yohanan/.cache/zig --seed 0xed7b0d62 -Doptimize=Debug run -- /home/yohanan/test.buzz
giann commented 4 months ago

Thanks for the kind words. I recently rewrote the AST structure so bugs like this are common. Thanks for the report.

giann commented 1 month ago

Resolved as a side effect of other changes