Skip to content

[sema] auto-enforce native compiler pitfall rules #729

@cs01

Description

@cs01

Problem

CLAUDE.md lists ~15 "patterns that crash native code" as prose rules. Every contributor must memorize them. Two have been converted to enforced sema passes (or-fallback-checker, type-assertion-checker), but the rest are honor-system.

Rules to enforce

High priority (proven crash classes)

  1. alloca for collection structs in class fields — detect alloca %Set, %Map, etc. stored into class fields. Should use GC_malloc. Sema pass or codegen-time check.
  2. ObjectArray element access loses type infoarr[i] returns i8*; accessing fields without as NamedType reads garbage. Could warn when fields are accessed on untyped ObjectArray elements.
  3. Inline `as { ... }` on opaque source — type-assertion-checker handles named-to-named casts, but `object as { field: string }` bypasses it. Sema pass pending.

Medium priority

  1. Arrow functions can't capture `this` — detect arrow functions that reference `this` and emit error
  2. Map<object, V> unsupported — detect Map instantiation with non-primitive key types
  3. Interface method dispatch broken — warn when calling methods on interface-typed fields (as opposed to class-typed)

Lower priority (rare triggers)

  1. Bulk class method additions — detect classes exceeding ~25 methods and warn
  2. Missing returns false positive — improve exhaustive switch detection in checkMissingReturns

Approach

Each rule = one sema pass file in src/semantic/, one error fixture in tests/fixtures/errors/. Ship incrementally, one per PR.

Success criteria

Every prose rule in CLAUDE.md "Patterns That Crash" either has an enforced sema pass or is marked as not-yet-reproducible.

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