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

Bogus property type narrowing when calling impure function #6407

Closed
dktapps opened this issue Jan 18, 2022 · 9 comments
Closed

Bogus property type narrowing when calling impure function #6407

dktapps opened this issue Jan 18, 2022 · 9 comments
Labels
Milestone

Comments

@dktapps
Copy link
Contributor

dktapps commented Jan 18, 2022

Bug report

This is an edge case I discovered while testing for a different bug in 1.4.1.

Code snippet that reproduces the problem

https://phpstan.org/r/09325d79-56ea-417e-825d-0314ebd22a19

Expected output

No error should be reported: not all values have been covered in the match, since the impure function call could result in a value change.

@dktapps
Copy link
Contributor Author

dktapps commented Jan 18, 2022

Forgive the confusing default match arm, this is a distilled sample of code from PM... the point is that it shouldn't be reported as an error.

@dktapps
Copy link
Contributor Author

dktapps commented Jan 18, 2022

This error is also sometimes accompanied by this on the last match arm for some reason:


 ------ ----------------------------------------------------------------------
  Line   src\network\mcpe\handler\InGamePacketHandler.php
 ------ ----------------------------------------------------------------------
  814    Match arm comparison between 4 and 4 is always true.

I've yet to identify what makes this show up; all I do know is that removing the default case shuts it up, but that's not an option.

@phpstan-bot
Copy link
Contributor

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

@@ @@
-PHP 8.0 – 8.1 (1 error)
+PHP 8.0 – 8.1 (2 errors)
 ==========
 
+51: Match arm comparison between 1|2|3|4 and 0 is always false.
 56: Match arm is unreachable because previous comparison is always true.
 
 PHP 7.1 – 7.4 (11 errors)
Full report

PHP 8.0 – 8.1 (2 errors)

Line Error
51 `Match arm comparison between 1
56 Match arm is unreachable because previous comparison is always true.

PHP 7.1 – 7.4 (11 errors)

Line Error
51 Syntax error, unexpected ',' on line 51
51 Syntax error, unexpected T_DOUBLE_ARROW on line 51
52 Syntax error, unexpected ',' on line 52
52 Syntax error, unexpected T_DOUBLE_ARROW on line 52
53 Syntax error, unexpected ',' on line 53
53 Syntax error, unexpected T_DOUBLE_ARROW on line 53
54 Syntax error, unexpected ',' on line 54
54 Syntax error, unexpected T_DOUBLE_ARROW on line 54
55 Syntax error, unexpected ',' on line 55
55 Syntax error, unexpected T_DOUBLE_ARROW on line 55
57 Syntax error, unexpected '}' on line 57

@dktapps
Copy link
Contributor Author

dktapps commented Jun 30, 2023

This new result seems more broken than before

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src#2787

@dktapps
Copy link
Contributor Author

dktapps commented Nov 27, 2023

Nothing showing from the issue bot?

@ondrejmirtes
Copy link
Member

Issue bot does not comment on closed issues.

@dktapps
Copy link
Contributor Author

dktapps commented Nov 27, 2023

Right, I checked the latest result and it seems to be all green. Thanks!

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 Dec 29, 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

3 participants