Skip to content

Commit

Permalink
Merge pull request #7093 from orklah/7090
Browse files Browse the repository at this point in the history
don't stop analyzing array, even if we already have a type and we can't create an object like
  • Loading branch information
orklah committed Dec 8, 2021
2 parents 604f47d + 574c8f7 commit eefdb95
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Expand Up @@ -453,10 +453,6 @@ private static function analyzeArrayItem(
}
}

if ($array_creation_info->item_value_atomic_types && !$array_creation_info->can_create_objectlike) {
return;
}

if ($item_value_type = $statements_analyzer->node_data->getType($item->value)) {
if ($item_key_value !== null && count($array_creation_info->property_types) <= 100) {
$array_creation_info->property_types[$item_key_value] = $item_value_type;
Expand Down
24 changes: 23 additions & 1 deletion tests/ArrayAssignmentTest.php
Expand Up @@ -1537,7 +1537,7 @@ function test(): array {
$x = [...test(), "a" => "b"];
',
'assertions' => ['$x' => 'non-empty-array<int|string, mixed>']
'assertions' => ['$x' => 'non-empty-array<int|string, mixed|string>']
],
'ArrayOffsetNumericSupPHPINTMAX' => [
'<?php
Expand Down Expand Up @@ -1693,6 +1693,28 @@ function unpackArray(array $data): array
[],
'8.1'
],
'unpackArrayWithTwoTypesNotObjectLike' => [
'<?php
function int(): int
{
return 0;
}
/**
* @return list<positive-int>
*/
function posiviteIntegers(): array
{
return [1];
}
$_a = [...posiviteIntegers(), int()];',
'assertions' => [
'$_a' => 'non-empty-list<int>',
],
[],
'8.1'
],
];
}

Expand Down

0 comments on commit eefdb95

Please sign in to comment.