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

?-> within an if statement doesn't correctly reduce the type #4690

Closed
BackEndTea opened this issue Mar 11, 2021 · 4 comments
Closed

?-> within an if statement doesn't correctly reduce the type #4690

BackEndTea opened this issue Mar 11, 2021 · 4 comments

Comments

@BackEndTea
Copy link
Contributor

Feature request

In this case, if I is null, or if I::foo returns false then we wont reach I::bar.

https://phpstan.org/r/d28d4d81-c04e-4a87-b727-22ce0ea16f96

@ondrejmirtes
Copy link
Member

I'd write it like this: https://phpstan.org/r/ca82dc23-c2c3-4cb3-8d4b-3fec059949b0

The single statement is telling too much on a single line, it's not immediately obvious what's going on.

@phpstan-bot
Copy link
Contributor

@BackEndTea After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-PHP 8.0 (1 error)
+PHP 8.0
 ==========
 
-16: Cannot call method bar() on I|null.
+No errors
 
 PHP 7.1 – 7.4 (2 errors)
 ==========
Full report

PHP 8.0

No errors

PHP 7.1 – 7.4 (2 errors)

Line Error
12 Syntax error, unexpected ')' on line 12
12 Syntax error, unexpected T_OBJECT_OPERATOR on line 12

@ondrejmirtes
Copy link
Member

Fixed by: phpstan/phpstan-src@6622401

@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 May 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants