Skip to content

typescript: a method passed by reference registers with the function that passes it - #1728

Merged
swapnilpaliwal-sd merged 2 commits into
0.1.7from
loop/ty-ts-method-reference-callback
Sep 29, 2026
Merged

swapnilpaliwal-sd merged 2 commits into
0.1.7from
loop/ty-ts-method-reference-callback

Conversation

@swapnilpaliwal-sd

Copy link
Copy Markdown
Contributor

A TypeScript instance method handed over without being called (this.m, this.m.bind(this), xs.forEach(this.m, this), el.addEventListener('x', this.m)) had no row from the function that passes it. A free function at the same position already got one.

  • method_value in value-flow.dl looks the member up on the receiver's type or shape, the same way an instance call does, and sees through .bind. It feeds handed_function (the callback_registered rows) and holder_holds_function.
  • Controls that must not change: an arrow that calls the method, .call/.apply, a data field, and a getter (read at that point). New golden case 80-method-passed-by-reference.
  • Envelope-only goldens gained correct value rows in cases 08, 21, 22, 62 and 73 (for example const b = f.bind(null); b() now reaches f).
  • Checked: TS golden suite 87/87 on the VM. Small TS apps: callbacks 49→51 edges, receiver-typing 46→49, nothing removed. Six other TS corpus apps and parser/src (37,719 edges) unchanged; parser/src took 146s before, 157s after.

…that passes it

`xs.forEach(this.handle, this)`, `el.addEventListener('click', this.onClick)` and
`setTimeout(this.onHover.bind(this))` hand an instance method over without calling it, and the
passer had no row for it, where a free function passed at the same position had one.
method_value reads the member off the receiver's type (or shape) the way an instance call does,
sees through `.bind`, and leaves getters, setters, data fields and `.call`/`.apply` alone.

Co-authored-by: axiomcode-bot[bot] <334110751+axiomcode-bot[bot]@users.noreply.github.com>
…ler reports

Co-authored-by: axiomcode-bot[bot] <334110751+axiomcode-bot[bot]@users.noreply.github.com>
@swapnilpaliwal-sd
swapnilpaliwal-sd merged commit 2f2cea3 into 0.1.7 Sep 29, 2026
12 checks passed
@swapnilpaliwal-sd
swapnilpaliwal-sd deleted the loop/ty-ts-method-reference-callback branch September 29, 2026 01:19
@swapnilpaliwal-sd swapnilpaliwal-sd mentioned this pull request Sep 29, 2026
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