add semantic pass to validate inline type assertion field order#78
Merged
Conversation
- new src/semantic/type-assertion-checker.ts validates that inline as { } assertions form a valid prefix of a declared interface in correct field order
- fix transformer.ts: as { type, property } on MemberAccessAssignmentNode needed object before property
- fix string-methods.ts: as { pattern, flags } on RegexNode needed type first
- fix type-inference.ts: as { expression, assertedType } on TypeAssertionNode needed type first
- fix variable-allocator.ts: as { className, typeArgs } on NewNode needed type, args before typeArgs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Add semantic pass to validate inline type assertion field order. Inline assertions like
(expr as { type: string; left: Expr; right: Expr })use their field positions as GEP indices in native code. If those fields don't form a valid prefix of the actual interface in the correct order, GEP reads wrong memory and causes segfaults.Changes
type-assertion-checker.ts): Validates all inline{ }type assertions with 2+ fields. For each assertion, finds matching interfaces and errors if the assertion doesn't form a valid consecutive prefix in exact field order.checkTypeAssertions()ingenerateParts()before codegen, alongside existing closure and union type checks.typefield first:handleReplace()string method — regex node assertionresolveMemberAccessType()— type assertion in type inferenceallocateSetType()— new expression assertionhandleExpressionStatement()(native parser) — member/index assignment assertionTest Plan
npm test— all tests passnpm run verify:quick— self-hosting passes (Stage 2 proves native codegen is correct)as { left; right }(missingtype), confirm detailed error and hint to fix it