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 #5578

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

False-positive UnusedVariable #5578

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

Comments

@gharlan
Copy link
Contributor

gharlan commented Apr 5, 2021

https://psalm.dev/r/d21bfc97cf

@psalm-github-bot
Copy link

I found these snippets:

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

function getPath(string $path): string {
    return $path;
}

/** @return resource|null */
function foo() {
    if (is_readable($path = getPath('/path/1')) || is_readable($path = getPath('/path/2'))) {
		return fopen($path, 'r');
    }
    
    return null;
}
Psalm output (using commit 517b203):

INFO: UnusedVariable - 9:64 - $path is never referenced or the value is not used

@muglug
Copy link
Collaborator

muglug commented Apr 5, 2021

This also manifests as a false-negative type error: https://psalm.dev/r/332f48c9cc

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/332f48c9cc
<?php

function getPath(): string|object {
    return rand(0, 1) ? "a" : new stdClass();
}

function foo(string $s) : string {
    if (($path = $s) || ($path = getPath())) {
		return $path;
    }
    
    return "b";
}
Psalm output (using commit 517b203):

INFO: UnusedVariable - 8:26 - $path is never referenced or the value is not used

@muglug muglug added the bug label Apr 5, 2021
@muglug muglug closed this as completed in 7080bc3 Apr 6, 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