-
-
Notifications
You must be signed in to change notification settings - Fork 863
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
PHPStan assumes function/method returns value even if it can throw an exception #3710
Comments
A better code snippet might be this: https://phpstan.org/r/cbd2c0cb-5b13-44e8-af1d-ce3bc6984456 Also if you look at this snippet (https://phpstan.org/r/ee4105dd-a1a1-45a8-9f44-ed1dd0cd03d9) it looks like PHPStan is half right. It knows that |
This is wrong – that line won't be reached if the |
I agree with @muglug, I am wrong about line 27. Please ignore that part of bug report. Sorry about about that. However line 22 is still an issue: https://phpstan.org/r/fc66daf3-efad-4edf-8a96-72dbd56e81b9 |
https://phpstan.org/r/b3328236-bda4-4ebb-92c3-7ada868b1d84 I bring my own example too. |
@DaveLiddament After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-22: If condition is always true.
+No errors |
@DaveLiddament After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-26: If condition is always true.
+No errors |
@DaveLiddament After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
27: Unreachable statement - code above always terminates.
-29: If condition is always true.
32: If condition is always false.
38: Unreachable statement - code above always terminates. Full report
|
@DaveLiddament After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-22: If condition is always true.
+No errors |
@scaytrase After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-21: Else branch is unreachable because ternary operator condition is always true.
-21: Strict comparison using !== between string and null will always evaluate to true.
+No errors |
Fixed by: phpstan/phpstan-src#481 |
Closes phpstan/phpstan#1597 Closes phpstan/phpstan#3617 Closes phpstan/phpstan#778 Closes phpstan/phpstan#2969 Closes phpstan/phpstan#3004 Closes phpstan/phpstan#3710 Closes phpstan/phpstan#3822 Closes phpstan/phpstan#505 Closes phpstan/phpstan#1670 Closes phpstan/phpstan#1219
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
Referring the the code snippet... It appears that PHPStan assumes that
$person
is always set. Given the methodcreatePersonButCouldFail
can throw an exception (and is annotated with@throws
), this will not always be the case.Code snippet that reproduces the problem
https://phpstan.org/r/671b1297-7856-4edf-871f-8f9e1d4f7169
Expected output
Expect 2 outcomes:
If condition is always true
) is not reportedCannot call method aMethod() on Person|null.
)The text was updated successfully, but these errors were encountered: