Skip to content

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
@ondrejmirtes ondrejmirtes merged commit 607f7f8 into phpstan:2.1.x Jul 17, 2025
416 of 419 checks passed
@ondrejmirtes
Copy link
Member

Nice, thank you!

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