Follow method calls through fields, declared types and returned values; new rule unbound-method #114
Loading…
Reference in a new issue
No description provided.
Delete branch "receivers-by-type"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Stacked on #110, which is stacked on #109. Merge those first; I'll rebase this one as they land.
The failure rules followed a method call only when the receiver's class was visible right where the call was made:
this,new C(), a module-level instance, or a local declared as exactlyC. Every other receiver was not followed, and not followed meant silent. So the most ordinary shape of application code was invisible:Receivers whose class is written down
The checker has no type checker, but in all of these the class is in the source, one hop away, and each now resolves to the same method the direct form does:
= new Repo(), assigned in the constructor, inheritedthis.repo.load()deps.repo.load()withdeps: DepsmakeRepo().load(),(await open()).load()readonlyfieldapi.users.load()x.value,x.name = vAll four failure rules use it: a propagating call, a dropped
Resultand a floating rejection are each reported through a field as they are on a direct call.New rule:
unbound-method(error, with a quick fix)A method that uses
this, taken off its object without being called or bound. This passestscand crashes at run time. Not reported: arrow-function fields, static methods, methods that never usethis,.bind(...),() => this.count(),forEach(fn, thisArg), and a method the constructor rebinds. The fix appends.bind(this).Also fixed
Following more receivers exposed four false
floating-rejectionfindings from older logic on an adopter's code: a promise also stored in an object literal and awaited on every path, and a call returned from one branch of?:. Both are now understood. A promise kept in a list, discarded in a?:, or only compared is still reported.What an adopter will notice
On an adopter's project the findings are identical before and after, compared finding by finding, from its entries (673) and from its directories (1,111). The checker does see more: 14 more functions are known to propagate. But the callers reach those methods through interfaces, or already catch the failures. Dynamic dispatch is the next PR, and that is where new findings are expected.
The whole-program pass on that project's largest app goes from 725 ms to 815 ms.
How it was checked
test:std,typecheck, the docs examples,test:vite, the docs site build and the soundness corpus pass.Repo | undefinedthrough?., destructuring from a typed field, a static factory, a setter,for...ofover a typed array. A first version missed(await f()).m(), a field holding an object literal, andsuper.resetdetached; all three are fixed.try, a parameter that shadows a field's name.unbound-method-this).Still not followed
Box<Repo>), elements read by index, namespace member chains.unbound-methodignores statement order: a method passed before the constructor line that binds it is not reported.Created with Claude Opus 5.5 (implementation) and Claude Fable 5.2 (review and acceptance tests) in Claude Code.
The failure rules followed a method call only when the receiver's class was visible at the call: `this`, `super`, `new C()`, a module-level instance, or a binding declared as exactly `C`. Every other receiver was silent, so the most ordinary shape of application code, a service holding its dependencies in fields (`this.repo.load(id)`), propagated nothing anywhere. A receiver is now written down as a value (analyze/receivers.rs) and a call on it as `Callee::Of`; the whole-program pass (project/receivers.rs) follows the declarations, across files, to the method `new Repo().load()` runs: - a field declared with the class: an annotation, `= new Repo()`, a constructor parameter property, `this.repo = new Repo()` in the constructor; inherited; - a property of a declared type (`deps.repo.load()` with `deps: Deps`, an alias, an interface, an object type, `Repo | undefined`), also destructured (`const { repo } = deps`, `function run({ repo }: Deps)`), and `const` copies (`const repo = this.repo`, `const self = this`); - a function or method declared to return the class (`makeRepo().load()`, `T` of an async one's `Promise<T>` once awaited), and chains of these; - a member chain into a module-level object literal (`api.users.load()`); - getters and setters: `x.value` runs `get value()`, `x.value = v` runs `set value(v)`, keyed `C#get value` / `C#set value`. Not followed: a receiver typed as an interface or a union of several types, an override through a value declared as the base class (left to the declared contracts of the next change), generic types, array and Map elements. Two causes of false floating-rejection findings that the newly known rejections exposed are fixed: a promise held in a binding and also stored in an object literal (`{ promise }`) or compared (`p === q`) still settles where every path awaits it, and `return c ? f() : undefined` (also `??`, `||`) returns `f()`'s promise. Following more receivers adds call sites; the failure and propagation passes now take a function's calls from an index (`calls_of`) instead of scanning the file's, and calls by span from another (`call_at`). Receivers are interned per file and resolved once each. Co-Authored-By: Claude Opus 5.5 <[email protected]>this, taken off its object 3fa088b421`queueMicrotask(this.tick)`, `items.forEach(this.tick)`, `return this.tick`, `const f = ticker.tick; f()` and `const { tick } = ticker; tick()` run the method with `this` undefined, and the first `this.x` throws TypeError. tsc, oxlint's preset and `safe-ts check` all passed them (the soundness corpus counted the class `unbound-method-this` as escaping). The places the by-name machinery already visits as a function used as a value (an argument, a return, an object or array literal, an assignment, a field's value, a JSX attribute), and a `const` copy or a destructuring, now record the method they name, through the same receivers the failure rules follow. The whole-program pass reports it (an error) when that method is an instance method of a module-level class whose body uses `this` or `super`: not an arrow-function field, a `static` method, a method that doesn't use `this`, a decorated one, one the constructor binds, `this.tick.bind(this)`, `() => this.tick()`, or `items.forEach(this.tick, this)`. The quick fix binds it (`.bind(<object>)`) where the object is `this`, `super` or a plain name; the meaning test runs it. `unbound-method-this` no longer escapes and comes out of escaping.txt. Co-Authored-By: Claude Opus 5.5 <[email protected]>Three receivers the previous two commits left silent: - `(await makeLater()).load("")` wasn't followed, while `const repo = await makeLater(); repo.load("")` was. The awaited call is now the same value as the local holding it (`Callee::Returned` from `member_target`, `Value::Returned` from `value_of`). - `private readonly api = { load(id) { ... } }` and then `this.api.load()` wasn't followed, while a module-level object literal and a field `= new Repo()` were. A `readonly` field's object literal is now keyed like a module-level one (`Holder#api.load`) and the field resolves to it. - `setTimeout(super.reset, 5)` was silent when the parent's constructor sets `this.reset = this.reset.bind(this)`: the exemption removed the method from the ones that use `this`. That assignment makes an own property of the instance; `super.reset` reads the prototype's method, still unbound. The exemption now applies only to a read through the instance (the constructor of the method's class, or of the object's class or one between). Co-Authored-By: Claude Opus 5.5 <[email protected]>efe87d75502f8e2d1626sionzee referenced this pull request2026-11-21 10:22:27 +01:00