Skip to content
Permalink
Browse files

Fix #1628 - improve behaviour of unset in loops

  • Loading branch information...
muglug committed May 13, 2019
1 parent f8b4b12 commit fe0f352132f798512ced19faf75cbfc84e4aabe7
@@ -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
@@ -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<string|int, int>}',
'$c' => 'array{0:array<int|string, int>}',
'$d' => 'array{0:array<int|string, int>}',
'$e' => 'array{0:array<string|int, int>}',
],
@@ -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<string|int, int>}',
'$c' => 'array{root:array<int|string, int>}',
'$d' => 'array{root:array<int|string, int>}',
'$e' => 'array{root:array<string|int, int>}',
],
@@ -572,7 +572,7 @@ function foo(?string $s) : string {
}
}'
],
'possiblyUpdateArrayAfterUnset' => [
'updateArrayAfterUnset' => [
'<?php
/**
* @param string[] $arr
@@ -583,6 +583,21 @@ function foo(string $s) : void {
if (count($dict)) {}
}'
],
'updateArrayAfterUnsetInLoop' => [
'<?php
/**
* @param string[] $arr
*/
function foo(array $arr) : void {
$dict = ["a" => 1, "b" => 2, "c" => 3];
foreach ($arr as $v) {
unset($dict[$v]);
}
if (count($dict)) {}
}'
],
];
}
@@ -421,6 +421,13 @@ public function providerTestValidTypeCombination()
'Traversable<mixed, mixed>&Iterator',
],
],
'objectLikePlusArrayEqualsArray' => [
'array<string, int>',
[
'array<"a"|"b"|"c", 1|2|3>',
'array{a:1|2, b:2|3, c:1|3}',
],
],
];
}

0 comments on commit fe0f352

Please sign in to comment.
You can’t perform that action at this time.