Skip to content

Conversation

@wenxuanjun
Copy link
Contributor

@wenxuanjun wenxuanjun commented Dec 25, 2025

This PR fixes critical stability issues including stack-use-after-return segfaults and runtime interface casting panics.

Previously, AST node factory methods (e.g., create_element) returned struct values. When these values were assigned to the PsiElement interface, 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 the ReferenceExpressionBase interface (e.g., src.analyzer.psi.PsiElementImpl cannot be cast to ...). So implemented ReferenceExpressionBase interface for Identifier and added a safe fallback wrapper for unknown node types to prevent panics.

Resolves #80, resolves #110, resolves #152, resolves #162.

Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this 🙇🏻 .

It will make v-analyzer a lot more stable and usable.

@spytheman spytheman merged commit ec9e97d into vlang:main Dec 25, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants