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 UnusedVariable for assignment in if #5640

Closed
gharlan opened this issue Apr 18, 2021 · 3 comments
Closed

False-positive UnusedVariable for assignment in if #5640

gharlan opened this issue Apr 18, 2021 · 3 comments
Labels

Comments

@gharlan
Copy link
Contributor

gharlan commented Apr 18, 2021

https://psalm.dev/r/a2c8c64a3e

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/a2c8c64a3e
<?php

abstract class Foo {
    abstract function validate(): bool|string;
    abstract function save(): bool|string;
    
    function bar(): void {
    	if (true === ($result = $this->validate()) && true === ($result = $this->save())) {
            echo 'ok';
        } elseif (is_string($result)) {
            echo $result;
        } else {
            echo 'error';
        }
    }
}
Psalm output (using commit ee778e9):

INFO: UnusedVariable - 8:62 - $result is never referenced or the value is not used

@muglug muglug added the bug label Apr 18, 2021
@muglug
Copy link
Collaborator

muglug commented Apr 18, 2021

Comparable false-negative InvalidReturn: https://psalm.dev/r/5858e7fc6e

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/5858e7fc6e
<?php

function bar(bool $result): bool {
    if ($result && ($result = rand(0, 1))) {
        return true;
    }

    return $result;
}
Psalm output (using commit ee778e9):

INFO: UnusedVariable - 4:21 - $result is never referenced or the value is not used

@muglug muglug closed this as completed in 642f2f4 Apr 18, 2021
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