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

False positive for RedundantCondition after update from 3.10.1 to 3.11.0 #3125

Closed
kubawerlos opened this issue Apr 12, 2020 · 2 comments
Closed
Labels

Comments

@kubawerlos
Copy link
Contributor

After update from 3.10.1 to 3.11.0 one false positive started to being reported, For a code;

<?php
class Foo
{
    public function test() : void
    {
        $x = $this->get();
        $i = 0;
        while (isset($x[$i]) && is_array($x[$i])) {
            echo $i;
            $i++;
        }
    }
    
    /**
     * @return array
     */
    private function get() : array
    {
        return [['a'], 'b', 'c', ['d']];
    }
}

The function get returns array that has mixed elements - string or an array, so is_array is needed.

https://psalm.dev/r/48ff1bea43

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/48ff1bea43
<?php
class Foo
{
    public function test() : void
    {
        $x = $this->get();
        $i = 0;
        while (isset($x[$i]) && is_array($x[$i])) {
            echo $i;
            $i++;
        }
    }
    
    /**
     * @return array
     */
    private function get() : array
    {
        return [['a'], 'b', 'c', ['d']];
    }
}
Psalm output (using commit 5bc9b09):

ERROR: RedundantCondition - 8:33 - Found a redundant condition when evaluating $x[$i] and trying to reconcile type 'array<array-key, mixed>' to array

@muglug muglug added the bug label Apr 12, 2020
@muglug muglug closed this as completed in e17cfd8 Apr 13, 2020
@kubawerlos
Copy link
Contributor Author

Thank you @muglug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants