Skip to content
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

callable type definition is not properly matched when using yield in a short arrow function #7031

Closed
gnutix opened this issue Apr 14, 2022 · 8 comments · Fixed by phpstan/phpstan-src#1422
Labels
Milestone

Comments

@gnutix
Copy link

gnutix commented Apr 14, 2022

Bug report

Hello there,

I've already noticed in the past that PHPStan tends to report inspections when checking against a callable type depending on how the closure is written at call-site. I've had the issue again today and managed to reproduce it in the playground.

Code snippet that reproduces the problem

https://phpstan.org/r/7dc2492d-309e-4249-95f7-5250786a4e2c

Expected output

No inspection. The 4 different syntaxes (short+return, short+yield, full+return, full+yield) should all produce the same results.

Did PHPStan help you today? Did it make you happy in any way?

As always, it helps with my confidence when doing refactorings. :)

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Apr 14, 2022
@gnutix
Copy link
Author

gnutix commented Apr 22, 2022

Another example I just ran into : https://phpstan.org/r/7b966730-9115-483d-aee6-a491901fdb1a

@ondrejmirtes You tagged it as easy fixes, any pointer as to how this could be fixed ? I might be willing to give it a try as it's quite impacting in my codebase (we use arrow functions a lot).

@ondrejmirtes
Copy link
Member

The root issue is this: https://phpstan.org/r/ede09df7-f502-4c7f-89d8-3220607e818a

Which means the problem is really specific only to arrow functions.

Inspecting the code reveals that the handling of closures is much more complex than the handling of arrow functions, and it looks like there's some specific code to yield as well: https://github.com/phpstan/phpstan-src/blob/25d07000ca183b35dfe089480b6bfed41e4c976a/src/Analyser/MutatingScope.php#L1660-L1765

So the handling of long anonymous functions needs to somehow be replicated for arrow functions as well.

@ondrejmirtes
Copy link
Member

I don't consider this a priority for myself or the project, but since it's blocking you, I'm willing to fix this for 500 EUR paid against an invoice I'd issue :)

@gnutix
Copy link
Author

gnutix commented Apr 22, 2022

Sorry, it's not really blocking, just "too bad it doesn't work". 🤷‍♂️
I'll see tomorrow if I can dedicate a few hours to this and try to contribute something!

@gnutix
Copy link
Author

gnutix commented Apr 22, 2022

Here are some other weird cases (using full function, not short arrow ones) :

Should I create separate issues / discussions for these ? (even though it all relates to "properly inferring the key of an iterable")

@ondrejmirtes
Copy link
Member

Looks like a separate issue, please open a new one.

@gnutix
Copy link
Author

gnutix commented May 30, 2022

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants