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

Second rand(1,x) results in incorrect error #3553

Closed
Fosse opened this issue Jun 30, 2020 · 4 comments
Closed

Second rand(1,x) results in incorrect error #3553

Fosse opened this issue Jun 30, 2020 · 4 comments
Labels
Milestone

Comments

@Fosse
Copy link

Fosse commented Jun 30, 2020

Bug report

It seems that a second rand() results in a false positive only when using rand(1, x). E.g. rand(0, 100) does not give an error.

Error:
Comparison operation "<" between int<5, max> and 5 is always false.

Code snippet that reproduces the problem

https://phpstan.org/r/f6cd6866-3de6-4034-8b7c-dc083bbc17c2

Another example, without the elseif:
https://phpstan.org/r/1db5d8ae-21df-46bd-8361-818e872964c0

Expected output

Expected output is no error. When rand(1, 100) is changed to something else like rand(0, 100) the error also disappears.

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Jun 30, 2020
@phpstan-bot
Copy link
Contributor

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

@@ @@
-9: Comparison operation "<" between int<5, max> and 5 is always false.
+No errors

@phpstan-bot
Copy link
Contributor

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

@@ @@
-10: Comparison operation "<" between int<5, max> and 5 is always false.
+No errors

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@d4edc59

@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 Apr 29, 2021
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