diff --git a/src/Symfony/Component/TypeInfo/Tests/Type/CollectionTypeTest.php b/src/Symfony/Component/TypeInfo/Tests/Type/CollectionTypeTest.php index 2b8d6031efdcc..739a484061e6c 100644 --- a/src/Symfony/Component/TypeInfo/Tests/Type/CollectionTypeTest.php +++ b/src/Symfony/Component/TypeInfo/Tests/Type/CollectionTypeTest.php @@ -90,6 +90,9 @@ public function testToString() $type = new CollectionType(new GenericType(Type::builtin(TypeIdentifier::ARRAY), Type::string(), Type::bool())); $this->assertEquals('array', (string) $type); + + $type = new CollectionType(Type::generic(Type::builtin(TypeIdentifier::ARRAY), Type::bool()), isList: true); + $this->assertEquals('list', (string) $type); } public function testAccepts() diff --git a/src/Symfony/Component/TypeInfo/Type/CollectionType.php b/src/Symfony/Component/TypeInfo/Type/CollectionType.php index a801f2b51f8d0..2df37c91e0817 100644 --- a/src/Symfony/Component/TypeInfo/Type/CollectionType.php +++ b/src/Symfony/Component/TypeInfo/Type/CollectionType.php @@ -179,6 +179,10 @@ public function accepts(mixed $value): bool public function __toString(): string { + if ($this->isList && $this->type->isIdentifiedBy(TypeIdentifier::ARRAY)) { + return 'list<'.$this->getCollectionValueType().'>'; + } + return (string) $this->type; } }