Skip to content

fix: remove 82 unnecessary as-unknown-as double casts in escape-analysis#147

Merged
cs01 merged 2 commits intomainfrom
fix-double-casts
Mar 9, 2026
Merged

fix: remove 82 unnecessary as-unknown-as double casts in escape-analysis#147
cs01 merged 2 commits intomainfrom
fix-double-casts

Conversation

@cs01
Copy link
Owner

@cs01 cs01 commented Mar 9, 2026

Summary

  • Removed all 82 as unknown as double-cast patterns in src/semantic/escape-analysis.ts
  • Replaced with direct as casts (e.g., stmt as unknown as VariableDeclarationstmt as VariableDeclaration)
  • All casts are from Statement/Expression union types to their constituent members — TypeScript accepts direct casts since the target types are part of the union
  • The unknown intermediate bypassed TypeScript's structural compatibility checks and gave the native compiler less type information to work with

Why this matters

  • as unknown as is a type erasure pattern that hides bugs from TypeScript — if a type assertion is structurally incompatible, TypeScript can't warn you
  • The native compiler uses type information from casts to determine struct layouts for GEP indices — as unknown loses this information
  • escape-analysis.ts runs as a semantic pass before codegen and is compiled during self-hosting

Test plan

  • TypeScript compiles clean (no type errors)
  • All 437 tests pass (node + native)
  • npm run verify:quick passes (Stage 0 + Stage 1 + tests)

🤖 Generated with Claude Code

cs01 and others added 2 commits March 8, 2026 22:49
@cs01 cs01 merged commit a8968ff into main Mar 9, 2026
12 checks passed
@cs01 cs01 deleted the fix-double-casts branch March 12, 2026 05:34
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