Repository navigation
Plugin AST: resolve class names in function, arrow function, union and intersection type declarations - #14134
Conversation
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.
✅ Performance: unchanged · Issues: unchanged
How to read this table
head db33804 · base ce04a73 (merge-base) · workflow run |
|
Context for why a plugin needs this. psalm/psalm-plugin-laravel builds the model schema from migration files: it walks their AST ( For closures that check reads either has to be skipped (the
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 |
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.
…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.
Psalm 7.10.0 ships vimeo/psalm#14134, which the arrow function Blueprint callback check relies on.
…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.
Class names used as parameter and return types did not get a
resolvedNameattribute in two cases:SimpleNameResolveronly resolved methods and closures)resolveType()only descended intoNullableTypeandName)Plugins that walk the AST (
Codebase::getStatementsForFile(),AfterCodebasePopulated) therefore sawParaminstead ofSome\Vendor\Param. Psalm's own analysis doesn't readresolvedName, so only plugins are affected.Before
After: every class name above resolves to
Some\Vendor\Param/Some\Vendor\Result.Tests:
CodebaseTest::signatureTypesOfFunctionLikesAreNameResolved(function, closure, arrow function) andCodebaseTest::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.