Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Dheu3 opened this issue Nov 13, 2023 · 2 comments
Open

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

Dheu3 opened this issue Nov 13, 2023 · 2 comments

Comments

@Dheu3
Copy link

Dheu3 commented Nov 13, 2023

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
Copy link
Owner

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
Copy link
Author

Dheu3 commented Nov 14, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants