Skip to content

Fix: an invokable object, a function name or an array passed as a Closure is only ArgumentTypeCoercion - #14657

Merged
alies-dev merged 1 commit into
vimeo:masterfrom
alies-dev:alies-dev/closure-param-only-closures
Nov 22, 2026
Merged

alies-dev merged 1 commit into
vimeo:masterfrom
alies-dev:alies-dev/closure-param-only-closures

Conversation

@alies-dev

Copy link
Copy Markdown
Collaborator

An invokable object, a function name or an array callable passed to a Closure parameter only gets ArgumentTypeCoercion, which isn't reported below errorLevel 4, although PHP throws a TypeError.

Before

<?php
class StringHandler { public function __invoke(string $value): int { return 1; } }

function takesClosure(Closure $closure): void {}

function f(StringHandler $h): void {
    takesClosure($h); // ArgumentTypeCoercion: expects Closure, but parent type callable(string):int provided
}

After

    takesClosure($h); // InvalidArgument: expects Closure, but StringHandler provided

…ay given to a Closure param

ArgumentAnalyzer and HighOrderFunctionArgHandler replaced such an argument with its callable before comparing it, and a callable is a parent type of Closure, so it only got ArgumentTypeCoercion although PHP throws a TypeError. The callable's method is still marked used.
@alies-dev alies-dev added the release:fix The PR will be included in 'Fixes' section of the release notes label Nov 22, 2026
@alies-dev alies-dev self-assigned this Nov 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: unchanged

Project Memory (MB) Wall (s) Issues Weighted (types) Taint Dead code
✅ laravel 1 768 69.9 $\color{gray}{\textsf{-0.2\%}}$ 25 691 52 996 682 0
✅ symfony 3 596 245.9 $\color{gray}{\textsf{-0.7\%}}$ 50 610 98 403 1 528 0
✅ doctrine-orm 380 14.1 $\color{gray}{\textsf{+3.4\%}}$ 3 481 6 143 0 0
✅ psl 617 17.0 $\color{gray}{\textsf{-3.4\%}}$ 1 375 5 615 1 0
✅ phpunit 455 14.2 $\color{gray}{\textsf{+0.4\%}}$ 1 731 3 410 18 0
✅ php-parser 226 9.4 $\color{gray}{\textsf{-0.2\%}}$ 17 154 21 245 0 0
✅ tempest 895 26.8 $\color{gray}{\textsf{+0.3\%}}$ 5 047 10 528 252 0
✅ amphp-amp 45 1.5 $\color{gray}{\textsf{+1.3\%}}$ 29 49 0 0
✅ webmozarts-assert 272 5.0 $\color{gray}{\textsf{+2.1\%}}$ 577 2 720 0 0
✅ guzzle-promises 44 1.6 $\color{gray}{\textsf{-2.4\%}}$ 155 434 2 0
✅ monolog 135 5.9 $\color{gray}{\textsf{+0.3\%}}$ 913 2 479 10 0
✅ drupal 4 839 229.9 $\color{gray}{\textsf{+0.3\%}}$ 97 591 169 293 583 0
✅ wordpress 2 038 142.3 $\color{gray}{\textsf{+6.1\%}}$ 142 704 676 684 461 1
Total 15 311 783.5 $\color{gray}{\textsf{+0.9\%}}$ 347 058 1 049 999 3 537 1
How to read this table
  • Memory: Psalm's own peak figure, threads=1. More than +5 % fails, unless the PR changes composer.json.
  • Wall: base and head run on the same runner; ±10 % is noise. Above +10 % warns, never fails. re-run: a reversed second run was taken and the faster kept.
  • Issues: head count over all categories, then $\color{red}{\textsf{+added}}$ $\color{green}{\textsf{-removed}}$ against base.
  • Weighted (types): type issues weighted by error level (levels 1–8 as is, always-errors 10, strictness checks 1). Taint and dead-code issues are not weighed. The projects' own code is pinned and their dependencies resolve identically for base and head, so a change means Psalm reports more, fewer or differently serious issues. A rise is not necessarily a regression.
  • Taint: head count of Tainted* issues, then $\color{orange}{\textsf{+added}}$ $\color{orange}{\textsf{-removed}}$ against base. Both are orange as either direction needs review: more can be new detection or false positives, fewer can be fixed false positives or lost detection.
  • Dead code: head count of unused-code issues, shown only when a run reported some (findUnusedCode). More is red, fewer is green.
  • Total: sum over the projects compared on both sides. Its wall time warns above +5 % (±5 % is noise); the other thresholds apply per project.
  • Colors: $\color{red}{\textsf{red}}$ past a fail or warn threshold (or more issues), $\color{green}{\textsf{green}}$ an improvement past noise (or fewer issues), $\color{orange}{\textsf{orange}}$ needs review, $\color{gray}{\textsf{gray}}$ noise.
  • Performance: regressed if a head run crashed or timed out or a memory or wall delta is red, else improved if one is green, else unchanged. Its icon is the check result: ❌ fail · ⚠️ warn · ✅ pass; the icon next to each project is that project's result, 💥 = not comparable: base crashed or timed out (counts as ⚠️).
  • Types (heading): direction of the total weighted change, increased · decreased · unchanged. Taint and Dead code (heading): added and removed counts, present only when non-zero. Informational, never fails the check.

head e650998 · base 322f84a (merge-base) · workflow run

@alies-dev
alies-dev merged commit d80ebf0 into vimeo:master Nov 22, 2026
72 of 74 checks passed
@alies-dev
alies-dev deleted the alies-dev/closure-param-only-closures branch November 22, 2026 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:fix The PR will be included in 'Fixes' section of the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant