aardappel / lobster

The Lobster Programming Language
http://strlen.com/lobster
2.24k stars 121 forks source link

SIGSEGV when function is passed as defult argument #251

Closed Hjagu09 closed 1 year ago

Hjagu09 commented 1 year ago

lobster crashes when a function parameter has an defult value:

def foo(bar = fn: 5):
    print(bar())

foo()

runing this program lobster crashes giving the output fish: Job 3, '~/git-apps/lobster/bin/lobster…' terminated by signal SIGSEGV (Address boundary error)

runing gdb over the core dump i get this:

Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x000055b1f262617b in lobster::Parser::ParseFunction(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool, bool, bool, lobster::UDT*) ()

environment linux mint 21 x86_64 up to date lobster compiled from source

aardappel commented 1 year ago

Thanks for reporting! Fix here: https://github.com/aardappel/lobster/commit/e57c12240b2858d0073017e2b0e43d1e9bdb5c64

The problem was related to that function value being parsed thinking foo was its surrounding scope, where really its scope is outside foo. That was not trivial to fix because of the order things get parsed, but should be working better now :)