diff --git a/src/Psalm/Internal/Type/TypeCombination.php b/src/Psalm/Internal/Type/TypeCombination.php index cd66e078bd1..671cb626003 100644 --- a/src/Psalm/Internal/Type/TypeCombination.php +++ b/src/Psalm/Internal/Type/TypeCombination.php @@ -272,6 +272,7 @@ public static function combineTypes( if (!$combination->has_mixed || $combination->mixed_from_loop_isset) { if ($combination->array_type_params && $combination->array_type_params[0]->allStringLiterals() + && $combination->array_always_filled ) { foreach ($combination->array_type_params[0]->getTypes() as $atomic_key_type) { if ($atomic_key_type instanceof TLiteralString) { @@ -281,6 +282,7 @@ public static function combineTypes( } $combination->array_type_params = []; + $combination->objectlike_sealed = false; } if (!$combination->array_type_params diff --git a/tests/ArrayAssignmentTest.php b/tests/ArrayAssignmentTest.php index 8c2f20fd199..e5a26fe65db 100644 --- a/tests/ArrayAssignmentTest.php +++ b/tests/ArrayAssignmentTest.php @@ -553,8 +553,8 @@ function fooFoo($a) { $e[0][$int] = 3; $e[0][$string] = 5;', 'assertions' => [ - '$b' => 'array{0:array{0:int, c:int}}', - '$c' => 'array{0:array{0:int, c:int}}', + '$b' => 'array{0:array}', + '$c' => 'array{0:array}', '$d' => 'array{0:array}', '$e' => 'array{0:array}', ], @@ -597,8 +597,8 @@ function fooFoo($a) { $e["root"][$int] = 3; $e["root"][$string] = 5;', 'assertions' => [ - '$b' => 'array{root:array{0:int, c:int}}', - '$c' => 'array{root:array{0:int, c:int}}', + '$b' => 'array{root:array}', + '$c' => 'array{root:array}', '$d' => 'array{root:array}', '$e' => 'array{root:array}', ], diff --git a/tests/RedundantConditionTest.php b/tests/RedundantConditionTest.php index dcb721d95f3..c83d85e2377 100644 --- a/tests/RedundantConditionTest.php +++ b/tests/RedundantConditionTest.php @@ -572,7 +572,7 @@ function foo(?string $s) : string { } }' ], - 'possiblyUpdateArrayAfterUnset' => [ + 'updateArrayAfterUnset' => [ ' [ + ' 1, "b" => 2, "c" => 3]; + + foreach ($arr as $v) { + unset($dict[$v]); + } + + if (count($dict)) {} + }' + ], ]; } diff --git a/tests/TypeCombinationTest.php b/tests/TypeCombinationTest.php index f6a2835b6e1..aff2312c04a 100644 --- a/tests/TypeCombinationTest.php +++ b/tests/TypeCombinationTest.php @@ -421,6 +421,13 @@ public function providerTestValidTypeCombination() 'Traversable&Iterator', ], ], + 'objectLikePlusArrayEqualsArray' => [ + 'array', + [ + 'array<"a"|"b"|"c", 1|2|3>', + 'array{a:1|2, b:2|3, c:1|3}', + ], + ], ]; }