psi: resolve memory corruption segfaults and runtime panics #174
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 PR fixes critical stability issues including
stack-use-after-returnsegfaults and runtime interface casting panics.Previously, AST node factory methods (e.g., create_element) returned struct values. When these values were assigned to the
PsiElementinterface, the interface's internal data pointer often pointed to temporary stack memory. Once the function returned, accessing these interface methods resulted in reading garbage memory, causing random segmentation faults. So modified to allocate them on heap, guaranteeing valid lifecycles for AST nodes.And in
SelectorExpression, unexpected AST node types caused runtime panics when blindly casting to theReferenceExpressionBaseinterface (e.g.,src.analyzer.psi.PsiElementImplcannot be cast to...). So implementedReferenceExpressionBaseinterface forIdentifierand added a safe fallback wrapper for unknown node types to prevent panics.Resolves #80, resolves #110, resolves #152, resolves #162.