Skip to content

union type check#64

Open
cs01 wants to merge 3 commits intomainfrom
worktree-union-type-check
Open

union type check#64
cs01 wants to merge 3 commits intomainfrom
worktree-union-type-check

Conversation

@cs01
Copy link
Owner

@cs01 cs01 commented Feb 26, 2026

Summary

  • Add a union type checker semantic pass that detects type alias unions with mixed LLVM representations (e.g., type Mixed = string | number) used as function/method parameters, which would silently miscompile and segfault at runtime
  • Add a closure mutation checker semantic pass that detects reassignment of variables after they've been captured by a closure, which produces silently incorrect results since ChadScript closures capture by value

Both passes run before IR generation in LLVMGenerator.generateParts() and exit with a clear error message pointing to the offending line.

Test plan

  • tests/fixtures/types/union-type-alias-error.ts — type alias union with mixed representations is a compile error
  • tests/fixtures/types/union-non-nullable-error.ts — inline union with different representations is a compile error
  • tests/fixtures/closures/closure-capture-mutation-error.ts — reassigning a captured variable is a compile error
  • tests/fixtures/closures/closure-capture-by-value-ok.ts — reassignment before capture is allowed

@cs01 cs01 force-pushed the worktree-union-type-check branch from ab5615e to d307d25 Compare February 26, 2026 08:26
@cs01 cs01 changed the title Worktree union type check union type check Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant