From d6044188c414f26e67c02437f91b5de84c754f38 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Fri, 19 Sep 2025 11:15:21 +0200 Subject: [PATCH 1/2] Add non regression test for 9386 --- .../InvalidComparisonOperationRuleTest.php | 5 ++++ .../PHPStan/Rules/Operators/data/bug-9386.php | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 tests/PHPStan/Rules/Operators/data/bug-9386.php 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..a8d789e7b1 --- /dev/null +++ b/tests/PHPStan/Rules/Operators/data/bug-9386.php @@ -0,0 +1,27 @@ +_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; +} From 595848ef31573018b7a0bd384a397a75a84c5a52 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Fri, 19 Sep 2025 11:26:13 +0200 Subject: [PATCH 2/2] Fix lint --- tests/PHPStan/Rules/Operators/data/bug-9386.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/PHPStan/Rules/Operators/data/bug-9386.php b/tests/PHPStan/Rules/Operators/data/bug-9386.php index a8d789e7b1..c015116741 100644 --- a/tests/PHPStan/Rules/Operators/data/bug-9386.php +++ b/tests/PHPStan/Rules/Operators/data/bug-9386.php @@ -1,4 +1,6 @@ -= 8.0 + +declare(strict_types = 1); namespace Bug9386;