Fix struct variable declaration crash in parser #249
Merged
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.
This commit changed read_body_statement() to use read_partial_var_decl() instead of read_full_var_decl when the type is already known, preventing double-parsing of struct types which was causing "Could not find type struct " errors at src/parser.c:728.
The root cause was that read_body_statement() had already consumed the struct type token via find_type(), but read_full_var_decl() attempted to parse the type again, leading to a token mismatch. Using read_partial_var_decl() correctly parses only the variable name when the type is already known.
Summary by Bito
This pull request fixes a critical bug in struct variable declaration handling by updating the read_body_statement() function to use read_partial_var_decl(). This change prevents double-parsing of struct types, enhancing type recognition. A comprehensive suite of tests has also been added to validate struct variable declarations across various scenarios.