1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix #3091 - simplify elseif negated clauses where possible

This commit is contained in:
Brown 2020-04-07 13:04:24 -04:00
parent 41b165c096
commit 61c979136f
2 changed files with 17 additions and 3 deletions

View File

@ -1517,9 +1517,11 @@ class IfAnalyzer
}
try {
$if_scope->negated_clauses = array_merge(
$if_scope->negated_clauses,
Algebra::negateFormula($elseif_clauses)
$if_scope->negated_clauses = Algebra::simplifyCNF(
array_merge(
$if_scope->negated_clauses,
Algebra::negateFormula($elseif_clauses)
)
);
} catch (\Psalm\Exception\ComplicatedExpressionException $e) {
$if_scope->negated_clauses = [];

View File

@ -1145,6 +1145,18 @@ class TypeAlgebraTest extends \Psalm\Tests\TestCase
echo $array["other"];',
'error_message' => 'InvalidArrayOffset',
],
'redundantTwoVarInElseif' => [
'<?php
class A {}
$from = rand(0, 1) ? new A() : null;
$to = rand(0, 1) ? new A() : null;
if ($from === null && $to === null) {
} elseif ($from !== null) {
} elseif ($to !== null) {}',
'error_message' => 'RedundantCondition',
],
];
}
}