Skip to content

Plugin AST: resolve class names in function, arrow function, union and intersection type declarations - #14134

Merged
alies-dev merged 2 commits into
vimeo:masterfrom
alies-dev:fix-arrow-function-name-resolution
Nov 18, 2026
Merged

alies-dev merged 2 commits into
vimeo:masterfrom
alies-dev:fix-arrow-function-name-resolution

Conversation

@alies-dev

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

Copy link
Copy Markdown
Collaborator

Class names used as parameter and return types did not get a resolvedName attribute in two cases:

  • signatures of named functions and arrow functions (SimpleNameResolver only resolved methods and closures)
  • members of union, intersection and DNF types in any signature (resolveType() only descended into NullableType and Name)

Plugins that walk the AST (Codebase::getStatementsForFile(), AfterCodebasePopulated) therefore saw Param instead of Some\Vendor\Param. Psalm's own analysis doesn't read resolvedName, so only plugins are affected.

Before

<?php
namespace Psalm\CurrentTest;

use Some\Vendor\Param;
use Some\Vendor\Result;

function f(Param $p): Result { return new Result(); }      // resolvedName: null, null
$c = function (Param $p): Result { return new Result(); }; // resolvedName: Some\Vendor\Param, Some\Vendor\Result
$a = fn (Param $p): Result => new Result();                // resolvedName: null, null
$u = function (Param|Result $p): Param&Result { ... };     // resolvedName: null for all four names

After: every class name above resolves to Some\Vendor\Param / Some\Vendor\Result.

Tests: CodebaseTest::signatureTypesOfFunctionLikesAreNameResolved (function, closure, arrow function) and CodebaseTest::compositeSignatureTypesOfFunctionLikesAreNameResolved (union, intersection and DNF types in a function, closure, arrow function and method); both fail without the fix except the plain closure control case.

Plugin use case: psalm/psalm-plugin-laravel#2350 (Schema::create('tags', fn (Blueprint $table) => ...)), see the comment below.

SimpleNameResolver only resolved parameter and return types of class methods and closures, so plugins reading the AST saw unresolved names for functions and arrow functions.
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Issues: unchanged

Project Memory (MB) Wall (s) Issues Weighted
✅ laravel 1 706 70.4 $\color{gray}{\textsf{+0.1\%}}$ 26 014 50 886
✅ symfony 3 620 207.8 $\color{gray}{\textsf{+4.0\%}}$ 50 786 99 128
✅ doctrine-orm 392 19.5 $\color{gray}{\textsf{+0.3\%}}$ 3 527 5 603
✅ psl 632 24.8 $\color{gray}{\textsf{+0.9\%}}$ 1 312 5 104
✅ phpunit 471 11.8 $\color{gray}{\textsf{+3.5\%}}$ 1 604 1 207
✅ php-parser 232 8.0 $\color{gray}{\textsf{-2.7\%}}$ 17 133 20 547
✅ tempest 892 21.3 $\color{gray}{\textsf{+0.9\%}}$ 4 930 9 279
✅ amphp-amp 61 2.3 29 49
✅ webmozarts-assert 284 5.5 $\color{gray}{\textsf{+0.7\%}}$ 577 2 720
✅ guzzle-promises 55 2.2 161 406
✅ monolog 153 6.2 $\color{gray}{\textsf{-0.3\%}}$ 907 2 191
✅ drupal 4 752 184.3 $\color{gray}{\textsf{+0.5\%}}$ 98 206 160 249
Total 13 251 564.0 $\color{gray}{\textsf{+1.8\%}}$ 205 186 357 369
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, then $\color{red}{\textsf{+added}}$ $\color{green}{\textsf{-removed}}$ against base.
  • Weighted: issues weighted by error level (levels 1–8 as is, always-errors 10, feature-specific and purity suggestions 0). 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.
  • 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{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 ⚠️).
  • Issues (heading): the total weighted change, increased · decreased · unchanged, followed by the issues added and removed across the projects, e.g. increased (+175 −128). If the weighted total is zero but issues were added or removed (those weighted 0 changed, or changes offset), it reads changed (+175 −128, weighted unchanged). Informational, never fails the check.

head db33804 · base ce04a73 (merge-base) · workflow run

@alies-dev alies-dev self-assigned this Nov 17, 2026
@alies-dev alies-dev added the release:fix The PR will be included in 'Fixes' section of the release notes label Nov 17, 2026
@alies-dev

Copy link
Copy Markdown
Collaborator Author

Context for why a plugin needs this.

psalm/psalm-plugin-laravel builds the model schema from migration files: it walks their AST (Codebase::getStatementsForFile()) and replays Schema::create() / Schema::table() callbacks. Before reading a callback body it checks that the callback's first parameter is typed Illuminate\Database\Schema\Blueprint, so callbacks of other classes that happen to be named create/table are not misread as table definitions.

For closures that check reads resolvedName. For an arrow function there is none, so

use Illuminate\Database\Schema\Blueprint;

Schema::create('tags', fn (Blueprint $table) => $table->string('name'));

either has to be skipped (the name column is lost and every $tag->name read is reported) or the plugin has to guess from the written name. psalm/psalm-plugin-laravel#2350 does the latter as a stopgap, which has two known gaps pinned in its tests:

  • use Foo\Blueprint; is accepted as Laravel's Blueprint (wrong class, columns read from an unrelated callback)
  • use Illuminate\Database\Schema\Blueprint as B; with fn (B $t) is declined, so the whole table is lost

With this PR both cases resolve exactly like closures, and the plugin drops the fallback once its Psalm floor includes the fix (tracked with a @todo-by pointing here).

@alies-dev alies-dev changed the title Resolve names in function and arrow function signatures Fix: resolve names in function and arrow function signatures Nov 17, 2026
resolveType() descended only into NullableType and Name, so class names inside union, intersection and DNF types kept no resolvedName attribute in methods, closures, functions and arrow functions.
@alies-dev alies-dev changed the title Fix: resolve names in function and arrow function signatures Resolve class names in function and arrow function signatures and in union and intersection types Nov 17, 2026
@alies-dev alies-dev changed the title Resolve class names in function and arrow function signatures and in union and intersection types Plugin AST: resolve class names in function, arrow function, union and intersection type declarations Nov 18, 2026
@alies-dev
alies-dev merged commit 2d8a48d into vimeo:master Nov 18, 2026
70 checks passed
@alies-dev
alies-dev deleted the fix-arrow-function-name-resolution branch November 18, 2026 00:08
alies-dev added a commit to psalm/psalm-plugin-laravel that referenced this pull request Nov 18, 2026
…backs

Psalm now resolves class names in arrow function signatures (vimeo/psalm#14134), so the written-name fallback and its known limitations are gone: an imported foreign Blueprint is declined and an aliased Blueprint is accepted, exactly like closures.
alies-dev added a commit to psalm/psalm-plugin-laravel that referenced this pull request Nov 18, 2026
Psalm 7.10.0 ships vimeo/psalm#14134, which the arrow function Blueprint callback check relies on.
alies-dev added a commit to psalm/psalm-plugin-laravel that referenced this pull request Nov 18, 2026
…hema::table()` callbacks (#2350)

* feat(schema): read Blueprint columns from arrow function migration callbacks

Schema::create(), Schema::table() and Blueprint::after() callbacks written as fn (Blueprint $table) => ... were ignored. Psalm's name resolver skips arrow function signatures, so the Blueprint parameter type check falls back to the written class name.

Fixes #2338

* docs(schema): link upstream fix for arrow function name resolution

Psalm's SimpleNameResolver skips ArrowFunction signatures; the written-name fallback in isForeignParamType() is a workaround until vimeo/psalm#14134 lands.

* style: apply rector and php-cs-fixer

* fix(schema): compare fully qualified arrow function Blueprint types exactly

Pins the written-name fallback limits in a KnownLimitation test and documents them; see vimeo/psalm#14134.

* fix(schema): rely on resolved names for arrow function Blueprint callbacks

Psalm now resolves class names in arrow function signatures (vimeo/psalm#14134), so the written-name fallback and its known limitations are gone: an imported foreign Blueprint is declined and an aliased Blueprint is accepted, exactly like closures.

* chore(deps): require Psalm 7.10 for arrow function name resolution

Psalm 7.10.0 ships vimeo/psalm#14134, which the arrow function Blueprint callback check relies on.

* fix(schema): drop the pure annotation from isForeignParamType

* build: require Psalm 7.10 and fix the findings it surfaces

- Bump vimeo/psalm to ^7.10.0 in composer.json and the tests.yml install step.
- Psalm 7.10 narrows exhausted instanceof checks to never (vimeo/psalm#14048): widen the container resolutions of url, translator and view to mixed so the runtime guards stay honest, and drop the unreachable Model guard around ReflectionClass<Model>::newInstanceWithoutConstructor().
- Expect the InvalidArgument 7.10 reports for a numeric-string factory() count in FactoryCountInferenceTest.

* style: apply rector and php-cs-fixer

* fix: keep the mixed container resolutions through Rector with @psalm-var

Rector strips a plain @var mixed, which brought back the Psalm 7.10 TypeDoesNotContainType findings.
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