Follow calls into methods, nested helpers, default and namespace imports, and re-exports #5

Merged
sionzee merged 1 commit from calls-beyond-named-functions into main 2026-11-03 21:32:56 +01:00
Owner

Closes the first item of README "Known gaps": calls were followed only into plain top-level named functions, so a PropagateError or a failure travelling through a method, a nested helper, ns.f(), a default import or a barrel file was dropped without a word.

What changed

  • Functions have keys (LocalAnalysis::functions): f, outer/inner (nested helper), C#m (instance method, also private C##m and arrow-function properties), C.m (static), obj.m (method of a module-level object literal), default (anonymous default export). Constructors are C#constructor; instance field initializers run as part of it.
  • Calls record what they target (Callee): a module-level name, a nested helper (resolved by binding after the walk, so calls before a hoisted declaration work), a member of a module-level binding, or a method of a known class. Calls to names bound inside functions that aren't helpers (parameters, local variables) are no longer looked up by name against top-level functions.
  • Receivers whose class is visible: this / super in methods, new C(), a module-level const x = new C() (also imported), a variable or parameter declared as exactly C. Methods are looked up along the extends chain, across files.
  • Imports and exports (project.rs): import x from, import * as ns, and export tables (export { f as g } from, export { default as f } from, export *, export * as ns, export default ...) are followed to the declaring module. PropagateError subclasses reached through re-exports are recognised too (before, export * from "./errors" in a barrel made throw new NotFound() a no-throw).
  • Messages name the callee as written (this.load, api.find, new Session).

Still not followed (documented in README "Known gaps", unhandled-failure and uncaught-propagation)

A method call on a receiver whose class isn't visible where it's made (interface or union type, this.repo.load(), a value returned from a call), an override in a subclass when the value is declared as the base class (dispatch goes to the class written in the code), getters and setters, functions passed around or stored, classes and objects declared inside functions, and member chains (ns.sub.f(), api.users.load()). These are left out, not guessed at. There is no docs/overview.md in the repo; README and the rule pages were updated instead.

Tests

  • New fixture tests/fixtures/calls (default export, namespace import, export {..} from, renaming re-export, export *, export * as, static/instance/private/inherited/super methods, object-literal methods with this, a module-level instance, a parameter typed with a class, a local new, field initializers, nested helper called before its declaration, legacy default export and method for unhandled-failure, an error class through a barrel). contexts now expects class methods and nested helpers to propagate, and keeps a class declared inside a function as not followed. Both fixtures fail against main's analysis code (checked by restoring crates/safe_ts_core/src from main).
  • cargo nextest run --workspace: 94 passed, 1 failed. The failure is fixtures_match_annotations on the features fixture (createDecipheriv at main.ts:55), which fails the same way on main: the node pack lists createDecipheriv but the fixture line has no expect. Not touched here.
  • npm run check (demo): output identical to main. safe-ts check examples/vue/src/main.ts: no problems.
  • npm run test:vite: passed. npm run test:docs: passed (docs examples, wasm, VitePress build).
  • npm run test:std: 115/116; feature-node/test/manifest.test.ts fails because the local Node (v26.13.0) has APIs the manifest doesn't list. Environment-dependent, unrelated.

Stacked on top of this: promise-returning functions (next PR), then instanceof narrowing in catch.

🤖 Generated with Claude Code

Closes the first item of README "Known gaps": calls were followed only into plain top-level named functions, so a `PropagateError` or a failure travelling through a method, a nested helper, `ns.f()`, a default import or a barrel file was dropped without a word. ## What changed - **Functions have keys** (`LocalAnalysis::functions`): `f`, `outer/inner` (nested helper), `C#m` (instance method, also private `C##m` and arrow-function properties), `C.m` (static), `obj.m` (method of a module-level object literal), `default` (anonymous default export). Constructors are `C#constructor`; instance field initializers run as part of it. - **Calls record what they target** (`Callee`): a module-level name, a nested helper (resolved by binding after the walk, so calls before a hoisted declaration work), a member of a module-level binding, or a method of a known class. Calls to names bound inside functions that aren't helpers (parameters, local variables) are no longer looked up by name against top-level functions. - **Receivers whose class is visible**: `this` / `super` in methods, `new C()`, a module-level `const x = new C()` (also imported), a variable or parameter declared as exactly `C`. Methods are looked up along the `extends` chain, across files. - **Imports and exports** (`project.rs`): `import x from`, `import * as ns`, and export tables (`export { f as g } from`, `export { default as f } from`, `export *`, `export * as ns`, `export default ...`) are followed to the declaring module. `PropagateError` subclasses reached through re-exports are recognised too (before, `export * from "./errors"` in a barrel made `throw new NotFound()` a `no-throw`). - Messages name the callee as written (`this.load`, `api.find`, `new Session`). ## Still not followed (documented in README "Known gaps", `unhandled-failure` and `uncaught-propagation`) A method call on a receiver whose class isn't visible where it's made (interface or union type, `this.repo.load()`, a value returned from a call), an override in a subclass when the value is declared as the base class (dispatch goes to the class written in the code), getters and setters, functions passed around or stored, classes and objects declared inside functions, and member chains (`ns.sub.f()`, `api.users.load()`). These are left out, not guessed at. There is no `docs/overview.md` in the repo; README and the rule pages were updated instead. ## Tests - New fixture `tests/fixtures/calls` (default export, namespace import, `export {..} from`, renaming re-export, `export *`, `export * as`, static/instance/private/inherited/`super` methods, object-literal methods with `this`, a module-level instance, a parameter typed with a class, a local `new`, field initializers, nested helper called before its declaration, legacy default export and method for `unhandled-failure`, an error class through a barrel). `contexts` now expects class methods and nested helpers to propagate, and keeps a class declared inside a function as not followed. Both fixtures fail against `main`'s analysis code (checked by restoring `crates/safe_ts_core/src` from `main`). - `cargo nextest run --workspace`: 94 passed, 1 failed. The failure is `fixtures_match_annotations` on the `features` fixture (`createDecipheriv` at `main.ts:55`), which fails the same way on `main`: the node pack lists `createDecipheriv` but the fixture line has no `expect`. Not touched here. - `npm run check` (demo): output identical to `main`. `safe-ts check examples/vue/src/main.ts`: no problems. - `npm run test:vite`: passed. `npm run test:docs`: passed (docs examples, wasm, VitePress build). - `npm run test:std`: 115/116; `feature-node/test/manifest.test.ts` fails because the local Node (v26.13.0) has APIs the manifest doesn't list. Environment-dependent, unrelated. Stacked on top of this: promise-returning functions (next PR), then `instanceof` narrowing in `catch`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The call graph only knew top-level named functions, so a PropagateError or a failure
travelling through `api.load()`, `this.save()`, a nested helper, `ns.f()`, a default
import or a barrel file was silently dropped: never propagated, never reported.

Functions now have keys (`f`, `outer/inner`, `C#m`, `C.m`, `obj.m`, `default`), calls
record what they target (a name, a nested helper, a member of a module-level binding, or
a method of a known class), and the whole-program pass follows imports through export
tables (`export { f as g } from`, `export *`, `export * as ns`, `export default`).
A method call is followed only when the receiver's class is visible where it is made
(`this`, `super`, `new C()`, a module-level instance, a variable or parameter declared
as exactly `C`); anything else is still left out rather than guessed at, and the README
says what. Error classes reached through re-exports now count as PropagateErrors too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
sionzee force-pushed calls-beyond-named-functions from 3553552a3d to 6abacf0e11 2026-11-03 21:29:22 +01:00 Compare
sionzee deleted branch calls-beyond-named-functions 2026-11-03 21:32:57 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Evobug/Safe-Ts!5
No description provided.