Skip to content

fix(args): unpacking an array shape with integer keys that is not a list passes as many arguments as it has keys - #14415

Merged
orklah merged 2 commits into
vimeo:masterfrom
jirkace:fix/13810-spread-int-key-shape
Nov 21, 2026
Merged

orklah merged 2 commits into
vimeo:masterfrom
jirkace:fix/13810-spread-int-key-shape

Conversation

@jirkace

@jirkace jirkace commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Unpacking an array shape with integer keys that is not a list reports TooFewArguments, and gives its values no types, although it passes one argument per key.

Before

function add(int $a, int $b): int { return $a + $b; }

/** @param array{2: int, 5: int} $c */
function f(array $c): int {
    return add(...$c); // TooFewArguments (twice), MixedArgument (twice)
}

After

    return add(...$c); // no issue

The values are passed in the order of the shape: method_exists(...$c) with array{1: string, 0: object} reports the swapped arguments (ArgumentTypeCoercion).

Fixes #13810

…ist passes as many arguments as it has keys vimeo#13810

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@jirkace

jirkace commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Behaviour change

  • Unpacking a sealed array shape whose keys are all integers but not a list (...$c with array{2: int, 5: int} or array{1: string, 0: object}) passes as many arguments as it has keys, in the order of the shape: no TooFewArguments for the parameters it fills, and each parameter is checked against the value at its position instead of mixed. Covered by new ArgTest cases, two of which fail on master.
  • It follows that method_exists(...$c) with array{1: string, 0: object} reports the swapped arguments (ArgumentTypeCoercion, InvalidArgument), which was suggested in the issue.
  • Unchanged, covered by a test: a shape with fewer keys than the required parameters still reports TooFewArguments; shapes with string keys and lists are unchanged (the position helper only converts a shape that has no fallback and only integer keys). A shape with optional integer keys (array{1?: int, 0: int}) is not converted (found by Bugbot: the conversion and the argument count disagreed): its values stay mixed, and it no longer reports TooFewArguments, as the count of arguments it passes is unknown (checked on a scratch project).
  • Not run: the full suite (CI), corpus benchmarks. Self-analysis: only the 2 PoolEventLoopDriverTest errors that master reports too here; the first version of the change flipped ComplexMethod of ArgumentAnalyzer::verifyType, so the conversion is done by a helper before the argument is checked.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: decreased

Project Memory (MB) Wall (s) Issues Weighted (types) Taint
✅ laravel 1 768 76.0 $\color{gray}{\textsf{+0.2\%}}$ 25 925 $\color{gray}{\textsf{+0}}$ $\color{green}{\textsf{-1}}$ 53 503 $\color{green}{\textsf{-10}}$ 682
✅ symfony 3 606 175.4 $\color{gray}{\textsf{+0.1\%}}$ 50 593 $\color{gray}{\textsf{+0}}$ $\color{green}{\textsf{-14}}$ 98 325 $\color{green}{\textsf{-77}}$ 1 528
✅ doctrine-orm 393 20.6 $\color{gray}{\textsf{+0.2\%}}$ 3 480 6 161 0
✅ psl 632 26.8 $\color{gray}{\textsf{-0.7\%}}$ 1 299 5 455 1
✅ phpunit 471 20.2 $\color{gray}{\textsf{+0.8\%}}$ 1 744 3 459 18
✅ php-parser 236 13.8 $\color{gray}{\textsf{-0.1\%}}$ 17 133 21 035 0
✅ tempest 905 36.0 $\color{gray}{\textsf{+0.1\%}}$ 5 043 10 505 252
✅ amphp-amp 61 2.3 $\color{gray}{\textsf{+0.9\%}}$ 29 49 0
✅ webmozarts-assert 288 5.5 $\color{gray}{\textsf{-0.2\%}}$ 577 2 720 0
✅ guzzle-promises 56 2.3 $\color{gray}{\textsf{-0.9\%}}$ 154 427 2
✅ monolog 153 6.4 $\color{gray}{\textsf{-1.4\%}}$ 903 2 403 10
✅ drupal 4 851 241.7 $\color{gray}{\textsf{+1.2\%}}$ 97 524 $\color{gray}{\textsf{+0}}$ $\color{green}{\textsf{-2}}$ 169 101 $\color{green}{\textsf{-11}}$ 583
Total 13 420 626.8 $\color{gray}{\textsf{+0.5\%}}$ 204 404 $\color{gray}{\textsf{+0}}$ $\color{green}{\textsf{-17}}$ 373 143 $\color{green}{\textsf{-98}}$ 3 076
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 +20 % 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. Thresholds apply per project, not to the total.
  • 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.
✅ laravel: issues +0 −1

Memory 1 768 → 1 768 MB (<0.1 %) · Wall 75.9 → 76.0 s (+0.2 %)

Weighted 53 513 → 53 503 (−10, −0.02 %): always −1

Issue type added removed
TooFewArguments 0 1

Removed (1)

  • src/Illuminate/Console/Concerns/HasParameters.php:35 TooFewArguments (error): Too few arguments for Illuminate\Console\Command::addOption - expecting name to be passed
✅ symfony: issues +0 −14

Memory 3 606 → 3 606 MB (<0.1 %) · Wall 175.2 → 175.4 s (+0.1 %)

Weighted 98 402 → 98 325 (−77, −0.08 %): L1 −7 · always −7

Issue type added removed
MixedArgument 0 7
TooFewArguments 0 7

Removed (14)

  • src/Symfony/Component/DependencyInjection/Loader/FileLoader.php:86 TooFewArguments (error): Too few arguments for Symfony\Component\Config\Loader\FileLoader::import - expecting resource to be passed
  • src/Symfony/Component/HttpKernel/Event/ControllerEvent.php:84 TooFewArguments (error): Too few arguments for method_exists - expecting method to be passed
  • src/Symfony/Component/HttpKernel/Event/ControllerEvent.php:84 TooFewArguments (error): Too few arguments for method_exists - expecting object_or_class to be passed
  • src/Symfony/Component/HttpKernel/Event/ControllerEvent.php:84 MixedArgument (error): Argument 1 of method_exists cannot be mixed, expecting class-string|object
  • src/Symfony/Component/HttpKernel/Event/ControllerEvent.php:84 MixedArgument (error): Argument 2 of method_exists cannot be mixed, expecting string
  • src/Symfony/Component/HttpKernel/Event/ControllerEvent.php:84 TooFewArguments (error): Too few arguments for ReflectionMethod::__construct - expecting objectOrMethod to be passed
  • src/Symfony/Component/HttpKernel/Event/ControllerEvent.php:84 MixedArgument (error): Argument 1 of ReflectionMethod::__construct cannot be mixed, expecting class-string|object
  • src/Symfony/Component/HttpKernel/Event/ControllerEvent.php:84 MixedArgument (error): Argument 2 of ReflectionMethod::__construct cannot be mixed, expecting null|string
  • src/Symfony/Component/Security/Http/RememberMe/RememberMeDetails.php:52 TooFewArguments (error): Too few arguments for Symfony\Component\Security\Http\RememberMe\RememberMeDetails::__construct - expecting expires to be passed
  • src/Symfony/Component/Security/Http/RememberMe/RememberMeDetails.php:52 TooFewArguments (error): Too few arguments for Symfony\Component\Security\Http\RememberMe\RememberMeDetails::__construct - expecting userIdentifier to be passed
  • … and 4 more
✅ drupal: issues +0 −2

Memory 4 851 → 4 851 MB (<0.1 %) · Wall 239.0 → 241.7 s (+1.2 %)

Weighted 169 112 → 169 101 (−11, −0.01 %): L1 −1 · always −1

Issue type added removed
MixedArgument 0 1
TooFewArguments 0 1

Removed (2)

  • core/includes/install.core.inc:2598 TooFewArguments (error): Too few arguments for Drupal\Core\Batch\BatchBuilder::addOperation - expecting callback to be passed
  • core/includes/install.core.inc:2598 MixedArgument (error): Argument 1 of Drupal\Core\Batch\BatchBuilder::addOperation cannot be mixed, expecting callable[impure]|string

head 55088fd · base a328b90 (merge-base) · workflow run

…lues vimeo#13810

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@jirkace

jirkace commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 55088fd. Configure here.

@orklah orklah added the release:fix The PR will be included in 'Fixes' section of the release notes label Nov 21, 2026
@orklah
orklah merged commit 6486030 into vimeo:master Nov 21, 2026
72 of 73 checks passed
@orklah

orklah commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

Thanks @jirkace!

alies-dev added a commit to psalm/psalm-plugin-laravel that referenced this pull request Nov 21, 2026
* build: require Psalm 7.14

- Psalm 7.14 changes what the type fixtures report (PHP deprecations, unrequired-package functions, mixed-widened templates), and the fixtures updated in this PR no longer pass on 7.13.
- Raise the floor in composer.json and in the Symfony Console job of tests.yml.

* test: give the type and emission fixtures the composer.json Psalm 7.14 needs

- Psalm 7.14 counts a vendor function as defined only if the composer.json next to the config requires its package (vimeo/psalm#14413); tests/Type and the EmissionApp fixture have none, so `now()`, `cache()`, `env()`, `trans()`, `route()` and `to_route()` became UndefinedFunction and `mixed` (22 type tests and `EmissionAppTest`).
- The type tests select a differently named `composer.fixture.json` through `COMPOSER`, which leaves the plugin's project-root detection (a `composer.json` in the working directory) untouched.

* test: expect the PHP deprecations Psalm 7.14 reports in collection callback fixtures

- `is_a($string, Class::class)` is deprecated since PHP 8.6 (DeprecatedFunction) and an implicitly nullable parameter since PHP 8.4 (DeprecatedSyntax); Psalm reports both regardless of the analysed PHP version (vimeo/psalm#14413).
- The fixtures keep those shapes because the narrowing of the two-argument `is_a()` and of a `= null` closure parameter is what they pin; the deprecation is now part of `--EXPECTF--`.

* test: pin that an unbounded template given to getOrPut() and queued() now resolves to mixed

- Psalm 7.14 no longer treats a bare template as decidably not a Closure for the `$value is callable` guard (vimeo/psalm#12672), so the result is widened with `mixed` and returning it as the template reports MixedReturnStatement; before, a possible Closure result stayed silent.
- Rename GetOrPutClosureDefaultKnownLimitation.phpt to GetOrPutClosureDefaultUnboundedTemplateTest.phpt (positive coverage) and rewrite the three stub docblocks that cited the limitation.

* test: pin the possibly-empty array-shape unpack of Paginator::fragment() as a known limitation

- Psalm 7.14 unpacks `array{0?: string}` like a `list<string>` (vimeo/psalm#14415), so the call no longer resolves both the getter and the setter branch of `fragment()`; 7.13.2 did.
- Rename PaginatorFragmentUnpackTest.phpt to PaginatorFragmentUnpackKnownLimitation.phpt and rewrite the docblocks of the stub and of RouteDomainKnownLimitation.phpt that cited the old behavior.

* test: suppress Psalm 7.14's static-call false positive on a trait constructor in the Blade taint fixture

- Psalm 7.14 analyses the synthetic constructor call for uninitialised properties as a static call on the parent's trait and reports InvalidStaticInvocation (a regression of vimeo/psalm#14413, reproducible without the plugin).
- `BladeComponentTaintTest::the_bridge_adds_no_non_taint_issue` asserts no other issue, so the fixture class suppresses it.

* fix: accept the value argument in Enumerable::when() and unless() callbacks

- Laravel's Enumerable interface docblock types the callbacks as callable($this) and $value as bool, but Conditionable calls $callback($this, $value) and accepts any value
- Psalm 7.13.2 keeps the concrete $this type in callable($this) (vimeo/psalm#14423), which surfaced the arity mismatch as InvalidScalarArgument
- Stub Enumerable::when() and unless() with the Conditionable signature

* docs: link the upstream Enumerable docblock fix from the when()/unless() stub

* test: link the filed Psalm issues from the workarounds and known limitations

- vimeo/psalm#14554 (trait constructor InvalidStaticInvocation), #14556 (array-shape unpack), #14555 (composer.json next to the config).
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.

Spreading an array shape with integer keys that isn't a list gives TooFewArguments

2 participants