diff --git a/src/Type/IntersectionType.php b/src/Type/IntersectionType.php index 851fb49a8b..e85ee03dc6 100644 --- a/src/Type/IntersectionType.php +++ b/src/Type/IntersectionType.php @@ -56,6 +56,10 @@ public function accepts(Type $otherType, bool $strictTypes): TrinaryLogic public function isSuperTypeOf(Type $otherType): TrinaryLogic { + if ($otherType instanceof IntersectionType && $this->equals($otherType)) { + return TrinaryLogic::createYes(); + } + $results = []; foreach ($this->getTypes() as $innerType) { $results[] = $innerType->isSuperTypeOf($otherType); diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index 33da205b75..3664a347ed 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -256,6 +256,12 @@ public function testBug3468(): void $this->assertCount(0, $errors); } + public function testBug3686(): void + { + $errors = $this->runAnalyse(__DIR__ . '/data/bug-3686.php'); + $this->assertCount(0, $errors); + } + /** * @param string $file * @return \PHPStan\Analyser\Error[] diff --git a/tests/PHPStan/Analyser/data/bug-3686.php b/tests/PHPStan/Analyser/data/bug-3686.php new file mode 100644 index 0000000000..586a62a771 --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-3686.php @@ -0,0 +1,39 @@ + int, \'b\' => int)|array(\'b\' => int, \'c\' => int)', ], + [ + [ + TypeCombinator::intersect(new StringType(), new HasOffsetType(new IntegerType())), + TypeCombinator::intersect(new StringType(), new HasOffsetType(new IntegerType())), + ], + IntersectionType::class, + 'string&hasOffset(int)', + ], + [ + [ + TypeCombinator::intersect(new ConstantStringType('abc'), new HasOffsetType(new IntegerType())), + TypeCombinator::intersect(new ConstantStringType('abc'), new HasOffsetType(new IntegerType())), + ], + IntersectionType::class, + '\'abc\'&hasOffset(int)', + ], ]; } @@ -2734,6 +2750,14 @@ public function dataIntersect(): array ConstantArrayType::class, 'array(\'a\' => int, \'b\' => int)', ], + [ + [ + new StringType(), + new HasOffsetType(new IntegerType()), + ], + IntersectionType::class, + 'string&hasOffset(int)', + ], ]; }