Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteffb4a7

Browse files
bug#60632 [TypeInfo] Fix merging collection value types with union types (mtarld)
This PR was merged into the 7.3 branch.Discussion----------[TypeInfo] Fix merging collection value types with union types| Q | A| ------------- | ---| Branch? | 7.3| Bug fix? | yes| New feature? | no| Deprecations? | no| Issues |Fix#60620| License | MITFix merging collection values types. To be properly merged, union types need to be spread, and it was not the case.Commits-------c0783c3 [TypeInfo] Fix merging collection value types with union types
2 parents1b70214 +c0783c3 commiteffb4a7

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

‎src/Symfony/Component/TypeInfo/Tests/TypeResolver/StringTypeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public static function resolveDataProvider(): iterable
7979
yield [Type::arrayShape(['foo' => Type::bool()], sealed:false),'array{foo: bool, ...}'];
8080
yield [Type::arrayShape(['foo' => Type::bool()], extraKeyType: Type::int(), extraValueType: Type::string()),'array{foo: bool, ...<int, string>}'];
8181
yield [Type::arrayShape(['foo' => Type::bool()], extraValueType: Type::int()),'array{foo: bool, ...<int>}'];
82+
yield [Type::arrayShape(['foo' => Type::union(Type::bool(), Type::float(), Type::int(), Type::null(), Type::string()),'bar' => Type::string()]),'array{foo: scalar|null, bar: string}'];
8283

8384
// object shape
8485
yield [Type::object(),'object{foo: true, bar: false}'];

‎src/Symfony/Component/TypeInfo/Type/CollectionType.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,27 @@ public static function mergeCollectionValueTypes(array $types): Type
6565
$boolTypes = [];
6666
$objectTypes = [];
6767

68-
foreach ($typesas$t) {
69-
// cannot create an union with a standalone type
70-
if ($t->isIdentifiedBy(TypeIdentifier::MIXED)) {
71-
return Type::mixed();
72-
}
68+
foreach ($typesas$type) {
69+
foreach (($typeinstanceof UnionType ?$type->getTypes() : [$type])as$t) {
70+
// cannot create an union with a standalone type
71+
if ($t->isIdentifiedBy(TypeIdentifier::MIXED)) {
72+
return Type::mixed();
73+
}
7374

74-
if ($t->isIdentifiedBy(TypeIdentifier::TRUE, TypeIdentifier::FALSE, TypeIdentifier::BOOL)) {
75-
$boolTypes[] =$t;
75+
if ($t->isIdentifiedBy(TypeIdentifier::TRUE, TypeIdentifier::FALSE, TypeIdentifier::BOOL)) {
76+
$boolTypes[] =$t;
7677

77-
continue;
78-
}
78+
continue;
79+
}
7980

80-
if ($t->isIdentifiedBy(TypeIdentifier::OBJECT)) {
81-
$objectTypes[] =$t;
81+
if ($t->isIdentifiedBy(TypeIdentifier::OBJECT)) {
82+
$objectTypes[] =$t;
8283

83-
continue;
84-
}
84+
continue;
85+
}
8586

86-
$normalizedTypes[] =$t;
87+
$normalizedTypes[] =$t;
88+
}
8789
}
8890

8991
$boolTypes =array_unique($boolTypes);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp