Skip to content

Fix: an intersection whose later member has __invoke isn't callable - #14610

Merged
alies-dev merged 10 commits into
vimeo:masterfrom
alies-dev:alies-dev/intersection-later-invoke
Nov 22, 2026
Merged

alies-dev merged 10 commits into
vimeo:masterfrom
alies-dev:alies-dev/intersection-later-invoke

Conversation

@alies-dev

@alies-dev alies-dev commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Psalm doesn't treat an intersection as callable when __invoke comes from a class that isn't its first member, in any form (a callable parameter, $h(...), $h($x), Closure::fromCallable(), array_map(), array_walk(), array_filter()). The intersection now behaves as that class alone.

Before

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

/** @param callable(string): int $callback */
function takesCallback(callable $callback): void {}

function f(Named&StringHandler $h): void {
    takesCallback($h); // InvalidArgument: expects callable(string):int, but Named&StringHandler provided
}

After

    takesCallback($h); // no issue

Part of #14588

… as callable vimeo#14588

The invokable branch of getCallableFromAtomic() looked up __invoke on the first member of an object type only, and only for classes. It now resolves the member that supplies __invoke (interfaces, enums and abstract classes of an invokable interface included), binds the receiver and method templates against it, and keeps the conditional return unresolved. Where several members have __invoke the callable is the first member's if that is a class, as before, and an intersection with none first is callable only if one of them has the signature expected. The callable param check and calls of $h(...) use the same supplier, so an interface or a later intersection member gives the signature of its __invoke.
…ions like a closure vimeo#14588

array_map() and the other array functions compared the element types with the parameters of a closure only, so an object whose __invoke takes another type was accepted silently once it counted as callable. They now resolve its __invoke callable, and take the implicit variadic flag of the method (func_get_args()) into account as they do for closures.
…rs takes the elements vimeo#14588

Where several members of an object have __invoke and the first has none, the array functions skipped the element check. They now report the callback unless one of the members takes the element types, with the comparison of the callable param check.
@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
…ass that has __invoke vimeo#14588

Interfaces and enums are no longer taken for the supplier of __invoke, so they are handled as before, and neither is the choice between several members. The supplier is the first class of the type that has __invoke. is_callable() keeps the object type of such an intersection, as it does for a plain class.
…ot a Closure param's argument vimeo#14588

The argument of a callable param is replaced by its callable early, which made an invokable object a parent type of a Closure param and gave it ArgumentTypeCoercion only, where PHP throws a TypeError. The replacement is skipped for a Closure param unless the argument is a Closure.
…and keep marking Closure param callables used vimeo#14588

An interface as the first member of an intersection that has __invoke is handled as before, whatever the later members have. The method an array or a string callable names is still marked as used when it is given to a Closure param, and a string or an object is no longer swapped for its callable there by the higher-order argument handler.
…InvalidArgument

A string is not a Closure, so it is rejected as such, not as a scalar of the wrong type.
@alies-dev
alies-dev marked this pull request as ready for review November 22, 2026 02:03
@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: unchanged

Project Memory (MB) Wall (s) Issues Weighted (types) Taint Dead code
✅ laravel 1 768 73.4 $\color{gray}{\textsf{+0.9\%}}$ 25 691 52 996 682 0
✅ symfony 3 596 259.4 $\color{gray}{\textsf{-0.4\%}}$ 50 610 98 403 1 528 0
✅ doctrine-orm 380 20.9 $\color{gray}{\textsf{-0.3\%}}$ 3 481 6 143 0 0
✅ psl 617 27.0 $\color{gray}{\textsf{+0.1\%}}$ 1 375 5 615 1 0
✅ phpunit 455 20.4 $\color{gray}{\textsf{-0.9\%}}$ 1 731 3 410 18 0
✅ php-parser 226 13.5 $\color{gray}{\textsf{-0.9\%}}$ 17 154 21 245 0 0
✅ tempest 895 37.4 $\color{gray}{\textsf{+0.5\%}}$ 5 047 10 528 252 0
✅ amphp-amp 45 0.9 $\color{gray}{\textsf{-1.1\%}}$ 29 49 0 0
✅ webmozarts-assert 272 2.6 $\color{gray}{\textsf{-0.4\%}}$ 577 2 720 0 0
✅ guzzle-promises 44 0.9 155 434 2 0
✅ monolog 135 3.2 $\color{gray}{\textsf{+0.6\%}}$ 913 2 479 10 0
✅ drupal 4 839 229.0 $\color{gray}{\textsf{+0.1\%}}$ 97 591 169 293 583 0
✅ wordpress 2 038 136.0 $\color{gray}{\textsf{-1.7\%}}$ 142 704 676 684 461 1
Total 15 311 824.7 $\color{gray}{\textsf{-0.3\%}}$ 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 3b96031 · base d80ebf0 (merge-base) · workflow run

@alies-dev alies-dev changed the title Fix: an intersection whose later member has __invoke isn't callable Fix: an intersection whose later member has __invoke isn't callable Nov 22, 2026
…s __invoke, nothing more vimeo#14588

An intersection whose __invoke comes from a later class behaves as that class alone: one helper finds the member, and the Closure param strictness, the element checks of object callbacks and the method template binding of the invokable path are removed again.
… before vimeo#14588

getInvokeMember() accepted any first member with __invoke, so an enum passed the callable gate while the resolver, which takes classes only, gave no signature to compare: the enum was accepted as any callable. The first member must be a class or an interface again.
…ction-later-invoke

# Conflicts:
#	tests/ArrayFunctionCallTest.php
#	tests/CallableTest.php
@alies-dev
alies-dev merged commit 1989996 into vimeo:master Nov 22, 2026
70 of 71 checks passed
@alies-dev
alies-dev deleted the alies-dev/intersection-later-invoke branch November 22, 2026 12:39
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