Skip to content

Commit 9f0da34

Browse files
phpstan-botclaude
andcommitted
Revert get_class() simplification in ObjectType::equals() to fix TemplateObjectType regression
The `get_class($type) !== static::class` check was too strict - it rejected TemplateObjectType instances that should be comparable by class name, since TemplateObjectType extends ObjectType but has no equals() override. This caused false `varTag.type` errors when using @var with generic template types. Reverts to explicit instanceof checks: reject EnumCaseObjectType and GenericObjectType (when $this is plain ObjectType), but allow other ObjectType subclasses like TemplateObjectType. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 72ec631 commit 9f0da34

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

phpstan-baseline.neon

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,15 +1474,21 @@ parameters:
14741474
path: src/Type/ObjectShapeType.php
14751475

14761476
-
1477-
rawMessage: Doing instanceof PHPStan\Type\Generic\GenericObjectType is error-prone and deprecated.
1477+
rawMessage: 'Doing instanceof PHPStan\Type\Enum\EnumCaseObjectType is error-prone and deprecated. Use Type::getEnumCases() instead.'
14781478
identifier: phpstanApi.instanceofType
14791479
count: 1
14801480
path: src/Type/ObjectType.php
14811481

1482+
-
1483+
rawMessage: Doing instanceof PHPStan\Type\Generic\GenericObjectType is error-prone and deprecated.
1484+
identifier: phpstanApi.instanceofType
1485+
count: 3
1486+
path: src/Type/ObjectType.php
1487+
14821488
-
14831489
rawMessage: 'Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.'
14841490
identifier: phpstanApi.instanceofType
1485-
count: 2
1491+
count: 3
14861492
path: src/Type/ObjectType.php
14871493

14881494
-

src/Type/ObjectType.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
use function array_map;
5757
use function array_values;
5858
use function count;
59-
use function get_class;
6059
use function implode;
6160
use function in_array;
6261
use function sprintf;
@@ -625,7 +624,15 @@ public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
625624

626625
public function equals(Type $type): bool
627626
{
628-
if (get_class($type) !== static::class) {
627+
if (!$type instanceof self) {
628+
return false;
629+
}
630+
631+
if ($type instanceof EnumCaseObjectType) {
632+
return false;
633+
}
634+
635+
if ($type instanceof Generic\GenericObjectType && !$this instanceof Generic\GenericObjectType) {
629636
return false;
630637
}
631638

0 commit comments

Comments
 (0)