Fix crash on pointer dereference after declaration #252
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The parser would crash with "Unexpected token" when a pointer dereference assignment (e.g.,
*p = 0
) appeared immediately after a pointer declaration in the same block. This is a common C pattern that was blocking normal code compilation.The issue occurred because the parser tried to interpret
*p
as a type declaration when it appeared after a pointer declaration likeint *p = &x;
. The ambiguity between * as a type modifier versus a dereference operator caused the crash.This fix adds lookahead logic to check if the identifier after
*
is a known type. Only if it is a type will the statement be treated as a declaration; otherwise it is handled as a pointer dereference.Summary by Bito
This pull request fixes a critical bug in the parser related to pointer dereference assignments after declarations by implementing additional lookahead logic. It ensures correct parsing behavior and adds new test cases to validate various pointer dereference scenarios, enhancing robustness.