Skip to content

Conversation

zonuexe
Copy link
Contributor

@zonuexe zonuexe commented Jun 13, 2024

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ClosureType::$returnType is bound to the union of the other elements of the array with the type of the callback. I'm looking for a way to get around that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To avoid binding the ClosureType::$returnType to a union with the results of other elements, I have replaced it with a direct call to the original function. I don't want to misuse the phpstan_cache_printer attribute, but there doesn't seem to be any other suitable source of the original function.

Copy link
Member

Choose a reason for hiding this comment

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

This entire code block isn't the right solution. You don't need to do any of that. You should be able to achieve the same thing with just:

$callback = $functionCall->getArgs()[0]->value;
$callbackReturnType = $scope->getType(new FuncCall($callback, [
    new Arg(new TypeExpr($constantArray->getValueTypes()[$i])),
]));

If that doesn't work for some expressions, then the root cause is elsewhere.

@zonuexe zonuexe force-pushed the feature/improve-array_map-type branch from b5cae3f to 31ae118 Compare June 27, 2024 18:27
@zonuexe zonuexe force-pushed the feature/improve-array_map-type branch from 31ae118 to b2dae42 Compare August 27, 2024 16:11
@ondrejmirtes ondrejmirtes changed the base branch from 1.11.x to 1.12.x January 11, 2025 12:41
@ondrejmirtes
Copy link
Member

Please fix the build and rebase the branch to fix conflicts, or close the PR. Thank you.

@zonuexe zonuexe marked this pull request as draft March 22, 2025 02:21
@zonuexe
Copy link
Contributor Author

zonuexe commented Jul 6, 2025

It looks better based on #4068. Thanks @VincentLanglet!

@zonuexe zonuexe closed this Jul 6, 2025
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

2 participants