Repository navigation
Allow @phpstan-type and @phpstan-import-type above functions and methods - #7295
Merged
Merged
Conversation
The aliases are seen by the PHPDoc and the body of the function or method, including inline @var tags, closures and anonymous classes inside it, and are unknown once it ends. They shadow the aliases of the class and of the functions around them, and an anonymous class's own aliases shadow them. They may mention the templates of the function and of its class, and the bounds and defaults of those templates may name them. FunctionTypeAliasesRule reports for them what LocalTypeAliasesRule reports for class aliases, and also an alias or an alias parameter that shadows a template in scope. Amp-Thread-ID: https://ampcode.com/threads/T-01a238be-4c1b-73d6-9750-3146e02793ea
The error for an invalid type in a type alias carries the reason of the ErrorType as a tip, like the PHPDoc tag rules do for unresolvable types, e.g. that a generic alias is given too few type arguments, or an argument outside the bound of its parameter. Amp-Thread-ID: https://ampcode.com/threads/T-01a238be-4c1b-73d6-9750-3146e02793ea
The message named the alias the cycle was reached again at instead of the one whose body passes the growing argument, so for Node<T> referring to Link<list<T>> it said that Link<T> refers to Link<T>. Amp-Thread-ID: https://ampcode.com/threads/T-01a238be-4c1b-73d6-9750-3146e02793ea
ondrejmirtes
force-pushed
the
function-type-aliases
branch
from
December 3, 2026 07:15
c943e91 to
3c77367
Compare
This was referenced Dec 3, 2026
Open
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type aliases can now be declared (
@phpstan-type,@psalm-type,@phan-type) and imported (@phpstan-import-type,@psalm-import-type) above functions and methods.@vartags, closures, and anonymous classes inside it. Once the function ends, the alias is unknown again.@template V of Box = Box).The new
FunctionTypeAliasesRule(level 0) reports for these aliases whatLocalTypeAliasesRulereports for class aliases. It also reports an alias, or a generic alias's parameter, that shadows a template in scope.Also in this PR:
Importing from a function or method (
from function doFoo) is not part of this PR.Refs phpstan/phpstan#9164
Issue bot shows these issues fixed; their reproducers are added as regression tests:
Closes phpstan/phpstan#13315
Closes phpstan/phpstan#12208
Closes phpstan/phpstan#9424