1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Only complain about redundant conditions if there’s one negated clause

This commit is contained in:
Matthew Brown 2017-12-18 00:47:36 -05:00
parent 4ff26cdd8f
commit 4b0cee6142
2 changed files with 3 additions and 27 deletions

View File

@ -216,18 +216,9 @@ class AlgebraChecker
) { ) {
$negated_formula2 = self::negateFormula($formula2); $negated_formula2 = self::negateFormula($formula2);
$is_reconcilable = true;
foreach ($formula2 as $clause) {
if (!$clause->reconcilable) {
$is_reconcilable = false;
break;
}
}
// remove impossible types // remove impossible types
foreach ($negated_formula2 as $clause_a) { foreach ($negated_formula2 as $clause_a) {
if ($is_reconcilable) { if (count($negated_formula2) === 1) {
foreach ($clause_a->possibilities as $key => $values) { foreach ($clause_a->possibilities as $key => $values) {
if (count($values) > 1 if (count($values) > 1
&& count(array_unique($values)) < count($values) && count(array_unique($values)) < count($values)

View File

@ -548,24 +548,9 @@ class TypeAlgebraTest extends TestCase
function takesA(A $a) : void {} function takesA(A $a) : void {}
function foo(?A $a) : void { function foo(?A $a) : void {
$c = rand(0, 1);
if (($a instanceof B || $a instanceof C) if (($a instanceof B || $a instanceof C)
&& ($a instanceof B || rand(0, 1)) && ($a instanceof B || $c)
) {
takesA($a);
}
}',
],
'instanceofInCNFOrFlippedOrder' => [
'<?php
class A {}
class B extends A {}
class C extends A {}
function takesA(A $a) : void {}
function foo(?A $a) : void {
if (($a instanceof B || rand(0, 1))
&& ($a instanceof B || $a instanceof C)
) { ) {
takesA($a); takesA($a);
} }