Merged
Conversation
… and class fields
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.
Language hardening: closures, computed writes, type safety
Fixes several crash-inducing codegen issues and adds compile-time guardrails for unsafe type patterns.
Unsafe union type rejection
The semantic analyzer now rejects union types where members have incompatible memory layouts (e.g.
string | number) in variable declarations and class fields. Nullable unions (string | null) remain allowed since null shares the pointer representation. This prevents silent memory corruption at runtime.Interface field checking is intentionally omitted — the native compiler can't handle the
iface.fields[i].namearray-of-objects access pattern during self-hosting.Inline lambda captures in array methods
arr.map(x => x + captured),arr.filter(...), andarr.forEach(...)now correctly capture outer variables. Previously, inline lambdas passed to array methods lost their closure environment, causing undefined values or segfaults.The fix uses a struct-of-arrays pattern (
getLastCaptureNames()/getLastCaptureTypes()) instead of array-of-objects to remain self-hosting compatible. The orchestrator allocates the env struct immediately after generating the arrow function, so array iteration codegen can pass it as the first argument.Computed property write (
obj[key] = value)Extends computed property access (read) with write support. Uses the same strcmp chain over known object keys, but emits
storeinstead ofload. Both string and numeric field values are handled, with type matching to skip incompatible branches.Type assertion field order fix
const typed = obj as { age: number; name: string }where the asserted type reorders fields relative to the object literal now works correctly. Previously, the GEP indices followed the assertion's field order instead of the actual struct layout, reading wrong fields and causing segfaults.The fix records the source variable name during type assertion codegen (
setLastTypeAssertionSourceVar) so thatallocateDeclaredInterfacecan inherit the original field order.Changes
src/analysis/semantic-analyzer.ts— union type checks for variable decls and class fieldssrc/codegen/expressions/access/index.ts—generateDynamicObjectAssignmentforobj[key] = valuesrc/codegen/expressions/arrow-functions.ts— struct-of-arrays capture info accessorssrc/codegen/expressions/orchestrator.ts— env struct allocation for inline lambdas; type assertion source trackingsrc/codegen/infrastructure/— new context methods for env ptr and assertion source varsrc/codegen/types/collections/array/— pass closure env through iteration/search/sort codegensrc/codegen/llvm-generator.ts— plumb new context methodsdocs/language/limitations.md— updated for computed property write, closures, union restrictionsSemanticAnalyzerunsafe union rejectionTest plan
npm test— all unit and compiler tests passnpm run verify— full 3-stage self-hosting succeeds