diff --git a/tests/PHPStan/Rules/Operators/InvalidComparisonOperationRuleTest.php b/tests/PHPStan/Rules/Operators/InvalidComparisonOperationRuleTest.php index 18f50c815f..3aec604741 100644 --- a/tests/PHPStan/Rules/Operators/InvalidComparisonOperationRuleTest.php +++ b/tests/PHPStan/Rules/Operators/InvalidComparisonOperationRuleTest.php @@ -205,6 +205,11 @@ public function testBug13001(): void ]); } + public function testBug9386(): void + { + $this->analyse([__DIR__ . '/data/bug-9386.php'], []); + } + public function testBug7280Comment(): void { $this->analyse([__DIR__ . '/data/bug-7280-comment.php'], []); diff --git a/tests/PHPStan/Rules/Operators/data/bug-9386.php b/tests/PHPStan/Rules/Operators/data/bug-9386.php new file mode 100644 index 0000000000..c015116741 --- /dev/null +++ b/tests/PHPStan/Rules/Operators/data/bug-9386.php @@ -0,0 +1,29 @@ += 8.0 + +declare(strict_types = 1); + +namespace Bug9386; + +trait BaseTrait { + protected false|int $_pos; + + public function myMethod():bool { + $pos = $this->_pos; + if ($pos === false) + return false; + if (($this instanceof BaseClass) && $this->length !== null) + return $pos >= $this->offset + $this->length; + return false; + } +} + +class BaseClass +{ + use BaseTrait; + protected ?int $length = null; + protected int $offset = 0; +} +class SecondClass +{ + use BaseTrait; +}