Skip to content

Commit 721ce7b

Browse files
herndlmondrejmirtes
authored andcommitted
Retain left and right types in equal and identical expression
1 parent a041124 commit 721ce7b

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Analyser/TypeSpecifier.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ public function specifyTypesInCondition(
317317
if ($types !== null) {
318318
return $types;
319319
}
320+
321+
return $this->create($expr->left, $exprLeftType, $context, false, $scope)->normalize($scope)
322+
->intersectWith($this->create($expr->right, $exprRightType, $context, false, $scope)->normalize($scope));
320323
}
321324

322325
} elseif ($expr instanceof Node\Expr\BinaryOp\NotIdentical) {
@@ -437,7 +440,10 @@ public function specifyTypesInCondition(
437440

438441
$leftTypes = $this->create($expr->left, $leftType, $context, false, $scope);
439442
$rightTypes = $this->create($expr->right, $rightType, $context, false, $scope);
440-
return $context->true() ? $leftTypes->unionWith($rightTypes) : $leftTypes->normalize($scope)->intersectWith($rightTypes->normalize($scope));
443+
444+
return $context->true()
445+
? $leftTypes->unionWith($rightTypes)
446+
: $leftTypes->normalize($scope)->intersectWith($rightTypes->normalize($scope));
441447
} elseif ($expr instanceof Node\Expr\BinaryOp\NotEqual) {
442448
return $this->specifyTypesInCondition(
443449
$scope,

tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeMethodCallRuleTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ public function testRule(): void
7272
'Call to method ImpossibleMethodCall\Foo::isSame() with stdClass and stdClass will always evaluate to true.',
7373
78,
7474
],
75+
[
76+
'Call to method ImpossibleMethodCall\Foo::isNotSame() with stdClass and stdClass will always evaluate to false.',
77+
81,
78+
],
79+
[
80+
'Call to method ImpossibleMethodCall\Foo::isSame() with *NEVER* and stdClass will always evaluate to false.',
81+
84,
82+
],
7583
]);
7684
}
7785

0 commit comments

Comments
 (0)