-
-
Notifications
You must be signed in to change notification settings - Fork 862
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
False positive on return null|void #2643
Comments
This bug report is missing a link to reproduction on phpstan.org. |
Hi, it doesn't make much sense to combine |
You're either not returning anything, or you're returning something. In that case, |
No, it cannot. As in that case the return statement must be present semantically. Thus you use Please adjust this tool to not false positive on these cases, as it otherwise compromises its usage on many projects. That would be very sad. |
Note: |
I understand, I’ll think about it.
On Fri, 6 Dec 2019 at 18:08, Mark Sch. ***@***.***> wrote:
Note:
If a project may decide to not allow this soft case (decide for hard
typehints), they can simple add a cs sniffer or other tooling to do so, but
for all others this is still not sth that should be disallowed by phpstan
false-positive reporting these things.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2643?email_source=notifications&email_token=AAAZTODA6MF3AA2HOEFOT63QXKBILA5CNFSM4JVBE4CKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGEXQRI#issuecomment-562657349>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAZTOENPGX7LWBK5HY5BD3QXKBILANCNFSM4JVBE4CA>
.
--
Ondřej Mirtes
|
Note: This is also well understood by IDEs, e.g. PHPStorm. We need this for several libraries and cannot otherwise continue migrating to PHPStan 0.12. It currently is a hard blocker. |
PHP 8's union types implementation doesn't allow |
// cc @nikic |
Exactly. |
The validity is currently not the question. Even now in PHP7 no one can and should actually typehint as such. As a 2nd point and side effect |
If we can have a config option to toggle this on/off that would also be fine IMO. Just that by default it now complains about something it should not complain (stay silent about as this is the scope of different tooling/syntax to assert). And this is the issue at hand. |
I disagree. |
I don't view PHP 8's implementation as a change from PHP 7. It is how it was always intended to be. It was just never implemented. |
You should change your code to return |
Exactly, I didnt say it should be allowed as type. I am referring to the docblock line only (which is not a type, it is a combination of documented types). Big difference.
That is exactly what in this case, with also no typehint in place, is not what should have to be forced. |
@GrahamCampbell If you are not using this semantic type doc pair (and it sounds like you never would), why do you care about this? |
I don't agree with this view. A union of types is a type, and void is not allowed in the union. The phpdoc is meant to document the type. Not the types. |
The docblock is also mainly for humans and IDEs/tooling to further intospect/use the code. So it is given/good standard/practice to add semantic additions on top of what you define as the true type. Again: This is only for the ommited typehint and as such, you will most likely have a CS sniff in place to not allow the combination there and then to force or auto-add the typehint |
Ran into the same problem for Drupal's Coder, our workaround is to ignore this specific message for now https://github.com/pfrenssen/coder/blob/8.x-3.x/phpstan.neon#L54 A return type |
Exactly :) If void is part of the types, it should just abort if there indeed no return statements inside the body. |
I was surprised that the other side was already fixed in PHPStan: phpstan/phpstan-src@80afe10 I now fixed the remaining case, e.g. We might rethink this when PHP 8 is out. PHPStan typically wants the same constraints from phpDoc types as from the native types (so that they can be automatically converted by other tools). |
Released as 0.12.5 :) |
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. |
Bug report
Framework controller actions usually don't have to return, the
|void
addition should suffice to silence PHPStan.But it complains with
Expected output
No error here. Only with
\Cake\Http\Response|null
I would expect the above message.The text was updated successfully, but these errors were encountered: