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

Allow returning null from a PHPDoc void union #10291

Closed
herndlm opened this issue Dec 12, 2023 · 8 comments
Closed

Allow returning null from a PHPDoc void union #10291

herndlm opened this issue Dec 12, 2023 · 8 comments

Comments

@herndlm
Copy link
Contributor

herndlm commented Dec 12, 2023

Bug report

See phpstan/phpstan-src#2778 (comment) or WordPress/WordPress-Coding-Standards#2416 / https://github.com/WordPress/WordPress-Coding-Standards/blob/5f0c8a7ebdde0314ea5e30f76375a10c7d6f3910/WordPress/Sniffs/WhiteSpace/ObjectOperatorSpacingSniff.php

just to minimize the risk I forget..

fyi @jrfnl (also a big phpcs fan here 😊, thx for your work!)

Code snippet that reproduces the problem

https://phpstan.org/r/12a90bd8-64db-4620-855c-23579d0085f6

Expected output

No errors.

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

No response

@staabm
Copy link
Contributor

staabm commented Dec 12, 2023

Maybe thats something we can error about in bleeding edge, but no longer error for non-bleeding-edge?

Or maybe move the whole void-to-null transformation behind bleeding edge entirely

@jrfnl
Copy link

jrfnl commented Dec 12, 2023

Thanks @herndlm !

I've updated the example a little and added a second related code sample too (though that doesn't seem to error in the sandbox):
https://phpstan.org/r/20bb00b6-236f-4c0a-bb72-81415f5e9127

@ondrejmirtes
Copy link
Member

This fixes the new issue introduced in the latest release: phpstan/phpstan-src@40c8fb2

I'm not sure what to do about Result of method HelloWorld::myrand() (void) is used. because that's been reported for a long time and didn't change recently. We'd have to do some kind of exception when void is typehinted only in PHPDoc, because otherwise it's not really valid code.

Also - I added WP CS into integration tests here so we're gonna now in the future when we'd break it with our changes :)

@jrfnl
Copy link

jrfnl commented Dec 13, 2023

@ondrejmirtes Thank you for the swift action!

I'm not sure what to do about Result of method HelloWorld::myrand() (void) is used. because that's been reported for a long time and didn't change recently.

I wouldn't worry about that one, we made a choice to ignore that (for the previously mentioned stability reasons) before.

I added WP CS into integration tests here so we're gonna now in the future when we'd break it with our changes :)

That's great to hear. In the future, I'm looking to see if I can raise the level for PHPCS itself too (currently at level 0). That will likely result in more reports 😉

@ondrejmirtes
Copy link
Member

Added PHPCS too :) c615993

@Brenneisen
Copy link

Brenneisen commented Dec 13, 2023

@ondrejmirtes I don't quite understand the change yet, but it seems that this is now causing problems in Larastan's unit tests. For example https://github.com/larastan/larastan/actions/runs/7197697590/job/19605436384?pr=1792 (larastan/larastan#1792).

@ondrejmirtes
Copy link
Member

I'd say these results are better and more precise and the test expectations need to be adjusted on Larastan's master.

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 Jan 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants