Skip to content

Improve return type of array map #4068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: 2.1.x
Choose a base branch
from

Conversation

VincentLanglet
Copy link
Contributor

From #3156

Closes phpstan/phpstan#11180
Closes #3156

@VincentLanglet VincentLanglet marked this pull request as ready for review June 20, 2025 23:39
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

$node->name instanceof FuncCall
&& $node->name->isFirstClassCallable()
&& $node->name->getAttribute('phpstan_cache_printer') !== null
&& preg_match('/\A(?<name>\\\\?[^()]+)\(...\)\z/', $node->name->getAttribute('phpstan_cache_printer'), $m) === 1
Copy link
Member

Choose a reason for hiding this comment

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

Why the original code with:

				return ParametersAcceptorSelector::selectFromArgs(
					$this,
					$node->getArgs(),
					$calledOnType->getCallableParametersAcceptors($this),
					null,
				)->getReturnType();

does not work here? That should be addressed instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I took the code from the previous PR but it might be improved indeed so I re-tried.

I tried to simplify/rewrite the code in order to show what was missing in the original code.
Now it should be more clear with https://github.com/phpstan/phpstan-src/pull/4068/files

There is nothing wrong with

ParametersAcceptorSelector::selectFromArgs(
					$this,
					$node->getArgs(),
					$calledOnType->getCallableParametersAcceptors($this),
					null,
				)

but the issue was the early getReturnType and the fact the DynamicReturnTypeExtension was not used in this case.

Is it better ?

@VincentLanglet VincentLanglet force-pushed the arrayMapReturnType branch 2 times, most recently from fbbcdeb to 218705b Compare July 10, 2025 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve the return type of array_map() for constant arrays
3 participants