mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Add more support for logical and/or
This commit is contained in:
parent
9579460c59
commit
7cd1b27ff1
@ -781,6 +781,7 @@ class IfChecker
|
||||
{
|
||||
if ($stmt instanceof PhpParser\Node\Expr\BinaryOp) {
|
||||
if ($stmt instanceof PhpParser\Node\Expr\BinaryOp\BooleanAnd ||
|
||||
$stmt instanceof PhpParser\Node\Expr\BinaryOp\LogicalAnd ||
|
||||
$stmt instanceof PhpParser\Node\Expr\BinaryOp\LogicalXor
|
||||
) {
|
||||
return self::getDefinitelyEvaluatedExpression($stmt->left);
|
||||
|
@ -43,7 +43,8 @@ class WhileChecker
|
||||
|
||||
// if the while has an or as the main component, we cannot safely reason about it
|
||||
if ($stmt->cond instanceof PhpParser\Node\Expr\BinaryOp &&
|
||||
$stmt->cond instanceof PhpParser\Node\Expr\BinaryOp\BooleanOr
|
||||
($stmt->cond instanceof PhpParser\Node\Expr\BinaryOp\BooleanOr ||
|
||||
$stmt->cond instanceof PhpParser\Node\Expr\BinaryOp\LogicalOr)
|
||||
) {
|
||||
// do nothing
|
||||
} else {
|
||||
|
@ -916,6 +916,8 @@ class ExpressionChecker
|
||||
|
||||
if ($stmt instanceof PhpParser\Node\Expr\BinaryOp\BooleanAnd
|
||||
|| $stmt instanceof PhpParser\Node\Expr\BinaryOp\BooleanOr
|
||||
|| $stmt instanceof PhpParser\Node\Expr\BinaryOp\LogicalAnd
|
||||
|| $stmt instanceof PhpParser\Node\Expr\BinaryOp\LogicalOr
|
||||
|| $stmt instanceof PhpParser\Node\Expr\BinaryOp\Equal
|
||||
|| $stmt instanceof PhpParser\Node\Expr\BinaryOp\NotEqual
|
||||
|| $stmt instanceof PhpParser\Node\Expr\BinaryOp\Identical
|
||||
|
@ -46,7 +46,9 @@ class TypeChecker
|
||||
$this_class_name,
|
||||
StatementsSource $source
|
||||
) {
|
||||
if ($conditional instanceof PhpParser\Node\Expr\BinaryOp\BooleanAnd) {
|
||||
if ($conditional instanceof PhpParser\Node\Expr\BinaryOp\BooleanAnd ||
|
||||
$conditional instanceof PhpParser\Node\Expr\BinaryOp\LogicalAnd
|
||||
) {
|
||||
$left_assertions = self::getFormula(
|
||||
$conditional->left,
|
||||
$this_class_name,
|
||||
@ -65,10 +67,14 @@ class TypeChecker
|
||||
);
|
||||
}
|
||||
|
||||
if ($conditional instanceof PhpParser\Node\Expr\BinaryOp\BooleanOr) {
|
||||
if ($conditional instanceof PhpParser\Node\Expr\BinaryOp\BooleanOr ||
|
||||
$conditional instanceof PhpParser\Node\Expr\BinaryOp\LogicalOr
|
||||
) {
|
||||
// at the moment we only support formulae in CNF
|
||||
|
||||
if (!$conditional->left instanceof PhpParser\Node\Expr\BinaryOp\BooleanAnd) {
|
||||
if (!$conditional->left instanceof PhpParser\Node\Expr\BinaryOp\BooleanAnd &&
|
||||
!$conditional->left instanceof PhpParser\Node\Expr\BinaryOp\LogicalAnd
|
||||
) {
|
||||
$left_clauses = self::getFormula(
|
||||
$conditional->left,
|
||||
$this_class_name,
|
||||
@ -78,7 +84,9 @@ class TypeChecker
|
||||
$left_clauses = [new Clause([], true)];
|
||||
}
|
||||
|
||||
if (!$conditional->right instanceof PhpParser\Node\Expr\BinaryOp\BooleanAnd) {
|
||||
if (!$conditional->right instanceof PhpParser\Node\Expr\BinaryOp\BooleanAnd &&
|
||||
!$conditional->right instanceof PhpParser\Node\Expr\BinaryOp\LogicalAnd
|
||||
) {
|
||||
$right_clauses = self::getFormula(
|
||||
$conditional->right,
|
||||
$this_class_name,
|
||||
|
Loading…
Reference in New Issue
Block a user