-
Notifications
You must be signed in to change notification settings - Fork 650
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 RedundantCondition
#7776
Comments
I found these snippets: https://psalm.dev/r/1b1ca51578<?php
/**
* @param DateTime[] $bar
*/
function foo(?DateTime $foo, array $bar): void {
if (
$foo && !in_array($foo, $bar, true)
|| !$foo && $bar
) {
return;
}
if ($foo) {
}
}
|
Scratch that, not sure what I was thinking there. Here's something that's actually useful though, doing a strict comparison against null fixes it. |
I found these snippets: https://psalm.dev/r/39b01f458c<?php
/** @param list<int> $ints */
function foobar(?int $int, array $ints): bool
{
if ($int === null) {
return true;
}
return in_array($int, $ints, true);
}
https://psalm.dev/r/37e040f7fe<?php
/** @param list<int> $ints */
function foobar(?int $int, array $ints): bool
{
if (!in_array($int, $ints, true)) {
return false;
}
return $int === null;
}
|
Well I |
I found these snippets: https://psalm.dev/r/3395485445<?php
function foo(?int $foo, int $bar): void {
if (
$foo && $foo !== 1
|| !$foo && $bar
) {
return;
}
if ($foo === null) {
}
}
|
The conjunctive normal form version (which Psalm uses internally) also shows the bug: https://psalm.dev/r/edc2283627 |
I found these snippets: https://psalm.dev/r/edc2283627<?php
function baz(?int $foo): void {
if (
(!$foo || $foo !== 5) && ($foo || rand(0,1)) && ($foo !== 5 || rand(0, 1))
) {
return;
}
if ($foo === null) {}
}
|
Fixed in the master branch |
The culrpit was bad logic here. It was simplifying |
@muglug Thanks for the quick fix. But shouldn't the fix target the |
We're starting to have big differences between 4.x and master. Fixing this in 4.x means basically fixing an old version then rebasing that on master and getting conflicts, so basically fixing it twice. Recent events kinda disrupted availability and motivation of the team, I was hoping Psalm 5 would be available by now. In the meantime, it means some bugs are getting fixed on master unfortunately. However, feel free to switch to our master branch and report us any bug that could appear! |
https://psalm.dev/r/1b1ca51578
The text was updated successfully, but these errors were encountered: