Skip to content

Commit d8a673a

Browse files
bug symfony#60961 [TypeInfo] Fix Type::fromValue with empty array (norkunas)
This PR was merged into the 7.3 branch. Discussion ---------- [TypeInfo] Fix `Type::fromValue` with empty array | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #... | License | MIT Without this, it fails with `Symfony\Component\TypeInfo\Exception\InvalidArgumentException: "int|string" is not a valid list key type.` Commits ------- cfcf666 [TypeInfo] Fix `Type::fromValue` with empty array
2 parents 65eb3eb + cfcf666 commit d8a673a

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/Symfony/Component/TypeInfo/Tests/TypeFactoryTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ public function offsetUnset(mixed $offset): void
278278
}
279279
};
280280

281+
yield [Type::array(Type::mixed()), []];
281282
yield [Type::list(Type::int()), [1, 2, 3]];
282283
yield [Type::dict(Type::bool()), ['a' => true, 'b' => false]];
283284
yield [Type::array(Type::string()), [1 => 'foo', 'bar' => 'baz']];

src/Symfony/Component/TypeInfo/TypeFactoryTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public static function fromValue(mixed $value): Type
443443

444444
$valueType = $valueTypes ? CollectionType::mergeCollectionValueTypes($valueTypes) : Type::mixed();
445445

446-
return self::collection($type, $valueType, $keyType, \is_array($value) && array_is_list($value));
446+
return self::collection($type, $valueType, $keyType, \is_array($value) && [] !== $value && array_is_list($value));
447447
}
448448

449449
if ($value instanceof \ArrayAccess) {

0 commit comments

Comments
 (0)