diff --git a/src/Type/IntersectionType.php b/src/Type/IntersectionType.php index ac8d3c7cb7..d3138156b9 100644 --- a/src/Type/IntersectionType.php +++ b/src/Type/IntersectionType.php @@ -22,7 +22,6 @@ use PHPStan\Type\Generic\TemplateType; use PHPStan\Type\Generic\TemplateTypeMap; use PHPStan\Type\Generic\TemplateTypeVariance; -use PHPStan\Type\Generic\TemplateUnionType; use PHPStan\Type\Traits\NonGeneralizableTypeTrait; use PHPStan\Type\Traits\NonRemoveableTypeTrait; use function array_map; @@ -144,10 +143,6 @@ public function isSubTypeOf(Type $otherType): TrinaryLogic public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLogic { - if ($acceptingType instanceof self || ($acceptingType instanceof UnionType && !$acceptingType instanceof TemplateUnionType)) { - return $acceptingType->accepts($this, $strictTypes); - } - $results = []; foreach ($this->getTypes() as $innerType) { $results[] = $acceptingType->accepts($innerType, $strictTypes); diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index 0b4b314dbf..6a83f4103f 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -859,6 +859,14 @@ public function testBug7275(): void $this->assertNoErrors($errors); } + public function testBug7500(): void + { + $errors = $this->runAnalyse(__DIR__ . '/data/bug-7500.php'); + $this->assertCount(1, $errors); + $this->assertSame('Method Bug7500\HelloWorld::computeForFrontByPosition() should return array but returns array.', $errors[0]->getMessage()); + $this->assertSame(38, $errors[0]->getLine()); + } + /** * @param string[]|null $allAnalysedFiles * @return Error[] diff --git a/tests/PHPStan/Analyser/data/bug-7500.php b/tests/PHPStan/Analyser/data/bug-7500.php new file mode 100644 index 0000000000..9c85c4a4b8 --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-7500.php @@ -0,0 +1,48 @@ + $tgs + * + * @return array + * + * @throws \Exception + */ + public function computeForFrontByPosition($tgs) + { + /** @phpstan-var array $res */ + $res = []; + + foreach ($tgs as $tgItem) { + $position = $tgItem->getPosition(); + + if (!isset($res[$position])) { + $res[$position] = $tgItem; + } else { + $tgItemToKeep = $this->compare($tgItem, $res[$position]); + $res[$position] = $tgItemToKeep; + } + } + ksort($res); + + return $res; + } + + /** + * @phpstan-template T of TgEntityInterface + * @phpstan-param T $nextTg + * @phpstan-param T $currentTg + * @phpstan-return T + */ + abstract protected function compare(TgEntityInterface $nextTg, TgEntityInterface $currentTg): TgEntityInterface; +}