aardappel / lobster

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

Crash when --errors in idents.h due to null parent #276

Open Dheu3 opened 8 months ago

Dheu3 commented 8 months ago

a.lobster:

def a
def b

lobster.exe --errors 2 a.lobster

Results in crash at https://github.com/aardappel/lobster/blob/master/dev/src/lobster/idents.h#L752

sf->lexical_parent = defsubfunctionstack.back()->parent->overloads.back();

Parent pointer null

aardappel commented 8 months ago

Thanks for reporting!

This is actually a really hard bug to fix, it appears. It would seem easy enough to add a null check, but that is not the right fix: parent is meant to be always initialized, and would only solve this particular problem, not many others that --errors can possibly cause.

The real problem is the way I quickly hacked in --errors can't work reliably. It catches the error exception and then attempts to continue. But that means the entire parser needs to be resilient against being aborted half way, i.e. any call that produce a parsing error must not be in the middle of building up state, such as in this case the start and end of setting up a new function. Worse, to be correct, in this case it would need to undo the new function upon any error.

That can probably be done, but will be a complicated audit/refactor of all parsing code.

Another solution may be to only allow this kind of error catching in more limited contexts, like between the start and end of a statement. That still doesn't solve everything.

Meanwhile, --errors is going to be possibly buggy. It probably should not be used generally.

Dheu3 commented 8 months ago

Thanks, no worries. Will wait for when the compiler is rewritten into lobster 😜