Skip to content

Commit

Permalink
incompatible-binary-operands
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-worman committed May 21, 2024
1 parent 20c204b commit e0f3f8b
Showing 1 changed file with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Psalm\Type\Atomic\TLiteralInt;
use Psalm\Type\Atomic\TLiteralString;
use Psalm\Type\Atomic\TNamedObject;
use Psalm\Type\Atomic\TObject;
use Psalm\Type\Union;
use UnexpectedValueException;

Expand Down Expand Up @@ -247,8 +248,8 @@ public static function analyze(
&& $statements_analyzer->getCodebase()->config->strict_binary_operands
&& $stmt_left_type
&& $stmt_right_type
&& !UnionTypeComparator::isContainedBy($codebase, $stmt_left_type, $stmt_right_type)
&& !UnionTypeComparator::isContainedBy($codebase, $stmt_right_type, $stmt_left_type)
&& (($stmt_left_type->isSingle() && $stmt_left_type->hasBool())
|| ($stmt_right_type->isSingle() && $stmt_right_type->hasBool()))
) {
IssueBuffer::maybeAdd(
new InvalidOperand(
Expand All @@ -259,6 +260,35 @@ public static function analyze(
);
}


if (
$stmt instanceof PhpParser\Node\Expr\BinaryOp\Equal
|| $stmt instanceof PhpParser\Node\Expr\BinaryOp\NotEqual
|| $stmt instanceof PhpParser\Node\Expr\BinaryOp\Greater
|| $stmt instanceof PhpParser\Node\Expr\BinaryOp\GreaterOrEqual
|| $stmt instanceof PhpParser\Node\Expr\BinaryOp\Smaller
|| $stmt instanceof PhpParser\Node\Expr\BinaryOp\SmallerOrEqual
&& $statements_analyzer->getCodebase()->config->strict_binary_operands
&& $stmt_left_type
&& $stmt_right_type
) {
if (
($stmt_left_type->hasObjectType() || $stmt_right_type->hasObjectType())

Check failure on line 276 in src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOpAnalyzer.php

View workflow job for this annotation

GitHub Actions / build

PossiblyNullReference

src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOpAnalyzer.php:276:39: PossiblyNullReference: Cannot call method hasObjectType on possibly null value (see https://psalm.dev/083)

Check failure on line 276 in src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOpAnalyzer.php

View workflow job for this annotation

GitHub Actions / build

PossiblyNullReference

src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOpAnalyzer.php:276:76: PossiblyNullReference: Cannot call method hasObjectType on possibly null value (see https://psalm.dev/083)
&& (
!UnionTypeComparator::isContainedBy($codebase, $stmt_left_type, $stmt_right_type)

Check failure on line 278 in src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOpAnalyzer.php

View workflow job for this annotation

GitHub Actions / build

PossiblyNullArgument

src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOpAnalyzer.php:278:89: PossiblyNullArgument: Argument 3 of Psalm\Internal\Type\Comparator\UnionTypeComparator::isContainedBy cannot be null, possibly null value provided (see https://psalm.dev/078)
|| !UnionTypeComparator::isContainedBy($codebase, $stmt_right_type, $stmt_left_type)
)
) {
IssueBuffer::maybeAdd(
new InvalidOperand(
'Cannot compare ' . $stmt_left_type->getId() . ' to ' . $stmt_right_type->getId(),
new CodeLocation($statements_analyzer, $stmt),
),
$statements_analyzer->getSuppressedIssues(),
);
}
}

if (($stmt instanceof PhpParser\Node\Expr\BinaryOp\Equal
|| $stmt instanceof PhpParser\Node\Expr\BinaryOp\NotEqual
|| $stmt instanceof PhpParser\Node\Expr\BinaryOp\Identical
Expand Down

0 comments on commit e0f3f8b

Please sign in to comment.