Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Inline the single-use type argument erasure into isValueOfGenericType
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
  • Loading branch information
2 people authored and VincentLanglet committed Sep 22, 2026
commit 36e6600d79b36de86654504624a6a3f3c329e572
22 changes: 8 additions & 14 deletions src/Type/Generic/GenericClassStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,26 +129,20 @@ public static function isValueOfGenericType(Type $genericType, string $className
$genericType = $genericType->getBound();
}

// We are transforming constant class-string to ObjectType. But we need to filter out
// an uncertainty originating in possible ObjectType's class subtypes.
return self::eraseTypeArguments($genericType)->isSuperTypeOf(new ObjectType($className));
}

/**
* A class-string carries a class name and never its type arguments, so the type
* arguments must not take part in the comparison against a constant class-string:
* `X::class` is a value of `class-string<X<int>>` and of `class-string<X<*>>` just
* like it is of `class-string<X>`.
*/
private static function eraseTypeArguments(Type $type): Type
{
return TypeTraverser::map($type, static function (Type $type, callable $traverse): Type {
// A class-string carries a class name and never its type arguments, so the type
// arguments must not take part in the comparison: `X::class` is a value of
// `class-string<X<int>>` and of `class-string<X<*>>` just like it is of `class-string<X>`.
$genericType = TypeTraverser::map($genericType, static function (Type $type, callable $traverse): Type {
if ($type instanceof GenericObjectType) {
return new ObjectType($type->getClassName(), $type->getSubtractedType());
}

return $traverse($type);
});

// We are transforming constant class-string to ObjectType. But we need to filter out
// an uncertainty originating in possible ObjectType's class subtypes.
return $genericType->isSuperTypeOf(new ObjectType($className));
}

public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
Expand Down