Skip to content

array_filter with a first-class callable can narrow its return type #3329

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

Merged
merged 1 commit into from
Sep 5, 2024

Conversation

takaram
Copy link
Contributor

@takaram takaram commented Aug 17, 2024

@staabm
Copy link
Contributor

staabm commented Aug 18, 2024

Just a random idea maybe worth investigating.

would it be possible to rewrite a first-class-callable at the AST level to e.g. a regular callable (or closure::fromCallable), so we don't need special cases für callable and first-class-callables in every phpstan extension…?

otherwise we would need a similar fix we have in this PR in other extensions, e.g. in array_map for phpstan/phpstan#9224

@ondrejmirtes
Copy link
Member

@staabm You're on the right track. I've recently started adding these things to CallableParametersAcceptor. If we added the right method to that interface, like public function getAsserts(): Assertions, we could simplify the extension by a lot + it'd help other places to be analysed correctly as well.

These assertions would be propagated to ClosureType when creating it from function or method in MutatingScope:.createFirstClassCallable.

This PR fixes array_filter extension, but a proper long-term solution is what I described here.

@ondrejmirtes ondrejmirtes changed the base branch from 1.11.x to 1.12.x September 5, 2024 19:30
@ondrejmirtes ondrejmirtes merged commit 3e52bb0 into phpstan:1.12.x Sep 5, 2024
19 of 20 checks passed
@takaram takaram deleted the bug-11337 branch September 6, 2024 01:04
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.

None yet

3 participants