1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Get or LHS clauses after evaluating statements

This commit is contained in:
Matthew Brown 2017-12-03 18:22:25 -05:00
parent f5ca4b1c52
commit 02dcb2be95
2 changed files with 35 additions and 15 deletions

View File

@ -895,21 +895,6 @@ class ExpressionChecker
} elseif ($stmt instanceof PhpParser\Node\Expr\BinaryOp\BooleanOr ||
$stmt instanceof PhpParser\Node\Expr\BinaryOp\LogicalOr
) {
$left_clauses = AlgebraChecker::getFormula(
$stmt->left,
$statements_checker->getFQCLN(),
$statements_checker
);
$rhs_clauses = AlgebraChecker::simplifyCNF(
array_merge(
$context->clauses,
AlgebraChecker::negateFormula($left_clauses)
)
);
$negated_type_assertions = AlgebraChecker::getTruthsFromFormula($rhs_clauses);
$pre_referenced_var_ids = $context->referenced_var_ids;
$context->referenced_var_ids = [];
@ -926,6 +911,21 @@ class ExpressionChecker
$new_referenced_var_ids = array_diff_key($new_referenced_var_ids, $new_assigned_var_ids);
$left_clauses = AlgebraChecker::getFormula(
$stmt->left,
$statements_checker->getFQCLN(),
$statements_checker
);
$rhs_clauses = AlgebraChecker::simplifyCNF(
array_merge(
$context->clauses,
AlgebraChecker::negateFormula($left_clauses)
)
);
$negated_type_assertions = AlgebraChecker::getTruthsFromFormula($rhs_clauses);
$changed_var_ids = [];
// while in an or, we allow scope to boil over to support

View File

@ -124,6 +124,26 @@ class RedundantConditionTest extends TestCase
'assertions' => [],
'error_levels' => ['PossiblyUndefinedVariable'],
],
'noRedundantConditionAfterFromDocblockRemoval' => [
'<?php
class A {
public function foo() : void{}
public function bar() : void{}
}
/** @return A */
function makeA() {
return new A;
}
$a = makeA();
if ($a === null) {
exit;
}
if ($a->foo() || $a->bar()) {}',
],
];
}