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

[bug] comparison does not work correctly with sorted arrays #6467

Closed
adaniloff opened this issue Jan 27, 2022 · 2 comments
Closed

[bug] comparison does not work correctly with sorted arrays #6467

adaniloff opened this issue Jan 27, 2022 · 2 comments
Labels
Milestone

Comments

@adaniloff
Copy link

Bug report

Version: 1.4.2
Issue: Comparison does not work correctly with sorted arrays

Given the following code block I got the following error message.

Code snippet that reproduces the problem

(See at: https://phpstan.org/r/5fadc22b-916a-4cdd-9752-45d0fbbeb576)

        $values = $sortedValues = [0.5, 1, 2, 0.8, 0.4];
        sort($sortedValues);
        $expected = $sortedValues[2] + 0.05; // note here that we get the value from the sorted array
        foreach (array_fill(0, 5, null) as $index => $null) {
             $success = $values[$index] < $expected;
        }

Actual output

The following error (which is wrong):

Comparison operation "<" between 0.4|0.5|0.8|1|2 and 2.05 is always true.

Expected output

The output should be fine and not throw an error since the sorted array 3rd element is 0.8, which is not 2.05 but 1.3.

Did PHPStan help you today? Did it make you happy in any way?

Yes of course :)

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src#2891

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 Feb 29, 2024
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

2 participants