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 e0f3f8b commit 149bfdc
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
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 @@ -261,8 +260,7 @@ public static function analyze(
}


if (
$stmt instanceof PhpParser\Node\Expr\BinaryOp\Equal
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
Expand All @@ -272,8 +270,7 @@ public static function analyze(
&& $stmt_left_type
&& $stmt_right_type
) {
if (
($stmt_left_type->hasObjectType() || $stmt_right_type->hasObjectType())
if (($stmt_left_type->hasObjectType() || $stmt_right_type->hasObjectType())

Check failure on line 273 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:273:39: PossiblyNullReference: Cannot call method hasObjectType on possibly null value (see https://psalm.dev/083)

Check failure on line 273 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:273: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 275 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:275: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)
Expand Down
2 changes: 2 additions & 0 deletions tests/PureAnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ public function __toString() {
* @psalm-pure
*/
function foo(string $s, A $a) : string {
/** @psalm-suppress InvalidOperand */
if ($a == $s) {}
return $s;
}',
Expand Down Expand Up @@ -778,6 +779,7 @@ public function __toString() {
* @psalm-pure
*/
function foo(string $s, A $a) : string {
/** @psalm-suppress InvalidOperand */
if ($a == $s) {}
return $s;
}',
Expand Down
1 change: 1 addition & 0 deletions tests/TypeReconciliation/ConditionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3283,6 +3283,7 @@ function getStrings(): array {
'preventWeakEqualityToObject' => [
'code' => '<?php
function foo(int $i, stdClass $s) : void {
/** @psalm-suppress InvalidOperand */
if ($i == $s) {}
}',
'error_message' => 'TypeDoesNotContainType',
Expand Down
1 change: 1 addition & 0 deletions tests/TypeReconciliation/RedundantConditionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,7 @@ class A {}
* @param A $a
*/
function foo($a, $b) : void {
/** @psalm-suppress InvalidOperand */
if ([] == $a) {}
}',
'error_message' => 'DocblockTypeContradiction',
Expand Down

0 comments on commit 149bfdc

Please sign in to comment.