Skip to content

Fix IterableType->equals(TemplateIterableType) #3991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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

-
Expand Down
3 changes: 2 additions & 1 deletion src/Type/IterableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
use Traversable;
use function array_merge;
use function get_class;
use function sprintf;

/** @api */
Expand Down Expand Up @@ -167,7 +168,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;
}

Expand Down
5 changes: 5 additions & 0 deletions tests/PHPStan/Generics/TemplateTypeFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -66,6 +67,10 @@ public function dataCreate(): array
new IntegerType(),
]),
],
[
new IterableType(new IntegerType(), new StringType()),
new IterableType(new IntegerType(), new StringType()),
],
];
}

Expand Down
Loading