From f06ddd66decb18796da0c66e84b465836c39b91d Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 13 May 2025 16:34:51 +0200 Subject: [PATCH 1/2] Fix IterableType->equals(TemplateIterableType) --- src/Type/IterableType.php | 2 +- tests/PHPStan/Generics/TemplateTypeFactoryTest.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Type/IterableType.php b/src/Type/IterableType.php index 2e6d26a381..6d3b10ac1d 100644 --- a/src/Type/IterableType.php +++ b/src/Type/IterableType.php @@ -167,7 +167,7 @@ public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsRes public function equals(Type $type): bool { - if (!$type instanceof self) { + if (get_class($type) !== static::class) { return false; } diff --git a/tests/PHPStan/Generics/TemplateTypeFactoryTest.php b/tests/PHPStan/Generics/TemplateTypeFactoryTest.php index 16fe1d24df..58af77cd3b 100644 --- a/tests/PHPStan/Generics/TemplateTypeFactoryTest.php +++ b/tests/PHPStan/Generics/TemplateTypeFactoryTest.php @@ -8,6 +8,7 @@ use PHPStan\Type\Generic\TemplateTypeScope; use PHPStan\Type\Generic\TemplateTypeVariance; use PHPStan\Type\IntegerType; +use PHPStan\Type\IterableType; use PHPStan\Type\MixedType; use PHPStan\Type\ObjectType; use PHPStan\Type\StringType; @@ -66,6 +67,10 @@ public function dataCreate(): array new IntegerType(), ]), ], + [ + new IterableType(new IntegerType(), new StringType()), + new IterableType(new IntegerType(), new StringType()), + ], ]; } From d463dcc20d5486925a92da43f10810c5e5fbf226 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 13 May 2025 16:39:13 +0200 Subject: [PATCH 2/2] fix build --- phpstan-baseline.neon | 2 +- src/Type/IterableType.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index a887358f52..a07ea29556 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1383,7 +1383,7 @@ parameters: - message: '#^Doing instanceof PHPStan\\Type\\IterableType is error\-prone and deprecated\. Use Type\:\:isIterable\(\) instead\.$#' identifier: phpstanApi.instanceofType - count: 2 + count: 1 path: src/Type/IterableType.php - diff --git a/src/Type/IterableType.php b/src/Type/IterableType.php index 6d3b10ac1d..2242c477a5 100644 --- a/src/Type/IterableType.php +++ b/src/Type/IterableType.php @@ -20,6 +20,7 @@ use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait; use Traversable; use function array_merge; +use function get_class; use function sprintf; /** @api */