Skip to content

PHP 8.0 - throw statement is now throw expression, it can throw at any point #8084

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

Closed
ryium opened this issue Sep 30, 2022 · 3 comments · Fixed by phpstan/phpstan-src#1990
Closed
Labels
Milestone

Comments

@ryium
Copy link

ryium commented Sep 30, 2022

Bug report

Version

  • PHP - 8.1.10
  • PHPStan - PHP Static Analysis Tool 1.8.6
    • level 9

https://wiki.php.net/rfc/throw_expression

Code snippet that reproduces the problem

https://phpstan.org/r/e01eb1f3-1bf1-465e-85b6-f66470182d50

Expected output

If an exception is thrown, processing is interrupted, but if not, processing should be assumed to continue and the type should be correctly guessed
In this case, array_shift($params) returns string|null

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

I <3 PHPStan!

@mad-briller
Copy link
Contributor

phpstan understands throw expressions already:
https://phpstan.org/r/ccc14bb8-c2af-4072-89e4-dbd5920b40a9

this seems to be caused by NodeScopeResolver caching the inference of the array_shift($params) expression as string instead of string|null due to the ?? throw ....
i've tried to poke around at it for a bit but can't get much further than this:

  1. the ArrayShiftFunctionReturnTypeExtension is only invoked once, despite array_shift being present twice in the snippet.
  2. if the specifyExpressionType is made to bail early for array_shift, then the extension is called more than once and returns the correct value string|null, but it is still seemingly ignored, and i'm not sure why

is this as simple as array_shift not being marked as impure?
array_shift is missing in the functionMetadata map which is typically where this information is stored right?
https://github.com/phpstan/phpstan-src/blob/1.9.x/resources/functionMetadata.php#L704-L706

@rvanvelzen
Copy link
Contributor

#8164 is basically the same issue

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Oct 26, 2022
ryium added a commit to ryium/phpstan-src that referenced this issue Nov 10, 2022

Verified

This commit was signed with the committer’s verified signature. The key has expired.
ondrejmirtes pushed a commit to ryium/phpstan-src that referenced this issue Jan 8, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
ondrejmirtes Ondřej Mirtes
@ondrejmirtes ondrejmirtes reopened this Jan 8, 2023
ondrejmirtes added a commit to phpstan/phpstan-src that referenced this issue Jan 8, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
ondrejmirtes Ondřej Mirtes
@github-actions
Copy link

github-actions bot commented Feb 9, 2023

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 Feb 9, 2023
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.

4 participants