Skip to content

[cleanup] replace multi-field inline 'as { ... }' casts with named AST types (pre-req for enforcement) #680

@cs01

Description

@cs01

Context

PR #679 adds a semantic check that rejects multi-field inline type assertions (as { field1: T; field2: T }), forcing use of named types from src/ast/types.ts. This prevents the class of silent-wrong bug where field order in the inline type doesn't match the LLVM struct layout.

The check is correct. But the compiler's own source has 371 multi-field inline casts that need to be cleaned up before the check can be enforced.

What to do

Replace patterns like:
```ts
// Before:
const typed = expr as { type: string; op: string; left: Expression; right: Expression };

// After:
const typed = expr as BinaryNode;
```

Top offending files (sorted by count):

  • src/codegen/expressions/access/member.ts — 22
  • src/semantic/closure-mutation-checker.ts — 21
  • src/codegen/llvm-generator.ts — 21
  • src/semantic/async-await-checker.ts — 19
  • src/codegen/infrastructure/variable-allocator.ts — 19
  • src/semantic/type-assertion-checker.ts — 18
  • src/codegen/statements/for-of.ts — 18
  • src/codegen/infrastructure/type-resolver/type-resolver.ts — 18
  • (and ~20 more files)

Named types available in src/ast/types.ts: BinaryNode, MemberAccessNode, IndexAccessNode, VariableNode, CallNode, MethodCallNode, TypeAssertionNode, InterfaceField, FunctionNode, ClassMethod, etc.

Once all 371 are fixed, re-open #679 to enforce the check.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions