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

Subsequent nullsafe method calls on nullable variable results in false positive #6922

Closed
egonolieux opened this issue Mar 28, 2022 · 4 comments
Labels
Milestone

Comments

@egonolieux
Copy link

Bug report

Subsequent nullsafe method calls on nullable variable results in false positive.

Code snippet that reproduces the problem

https://phpstan.org/r/6ec02114-a3fc-4815-b655-7c688e67c445

Expected output

No error expected; false positive.

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Mar 28, 2022
@janchaloupka
Copy link

Hello I have also encountered this issue.

I have tried to narrow down the problem and I found that PHPStan correctly assumes the type if the (possible null) bool value is compared to TRUE but throws an error if compared to FALSE. Since both comparisons are strict I believe this to be a bug.

Here is the issue demonstrated using the PHPStan playground:

Strict comparison with FALSE value (incorrect type assumed).
https://phpstan.org/r/1f061693-59d3-4205-b910-1e2822f9d499

Strict comparison with TRUE value (everything works as expected).
https://phpstan.org/r/cc552cae-25f0-4a5e-8c01-80ef681a4278

@phpstan-bot
Copy link
Contributor

@egonolieux After the latest push in 1.11.x, PHPStan now reports different result with your code snippet:

@@ @@
-20: Using nullsafe method call on non-nullable type Configuration. Use -> instead.
+No errors

@phpstan-bot
Copy link
Contributor

@janchaloupka After the latest push in 1.11.x, PHPStan now reports different result with your code snippet:

@@ @@
-PHP 8.1 – 8.2 (1 error)
+PHP 8.1 – 8.2
 ==========
 
-19: Using nullsafe property access on non-nullable type Person. Use -> instead.
+No errors
 
 PHP 7.1 – 8.0 (1 error)
 ==========
 
  6: Syntax error, unexpected T_STRING, expecting T_VARIABLE on line 6
Full report

PHP 8.1 – 8.2

No errors

PHP 7.1 – 8.0 (1 error)

Line Error
6 Syntax error, unexpected T_STRING, expecting T_VARIABLE on line 6

Copy link

github-actions bot commented Dec 4, 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 Dec 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants