1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Fix array_replace type

This commit is contained in:
ElisDN 2022-01-25 14:43:28 +03:00
parent f1c4b62f5c
commit 9f01c16ae9
2 changed files with 11 additions and 5 deletions

View File

@ -44,6 +44,8 @@ class ArrayMergeReturnTypeProvider implements FunctionReturnTypeProviderInterfac
return Type::getMixed();
}
$is_replace = mb_strcut($event->getFunctionId(), 6, 7) === 'replace';
$inner_value_types = [];
$inner_key_types = [];
@ -104,7 +106,11 @@ class ArrayMergeReturnTypeProvider implements FunctionReturnTypeProviderInterfac
foreach ($unpacked_type_part->properties as $key => $type) {
if (!is_string($key)) {
$generic_properties[] = $type;
if ($is_replace) {
$generic_properties[$key] = $type;
} else {
$generic_properties[] = $type;
}
continue;
}

View File

@ -210,9 +210,9 @@ class ArrayFunctionCallTest extends TestCase
],
'arrayMergeIntArrays' => [
'<?php
$d = array_merge(["a", "b", "c"], [1, 2, 3]);',
$d = array_merge(["a", "b", "c", "d"], [1, 2, 3]);',
'assertions' => [
'$d' => 'array{0: string, 1: string, 2: string, 3: int, 4: int, 5: int}',
'$d' => 'array{0: string, 1: string, 2: string, 3: string, 4: int, 5: int, 6: int}',
],
],
'arrayMergePossiblyUndefined' => [
@ -266,9 +266,9 @@ class ArrayFunctionCallTest extends TestCase
],
'arrayReplaceIntArrays' => [
'<?php
$d = array_replace(["a", "b", "c"], [1, 2, 3]);',
$d = array_replace(["a", "b", "c", "d"], [1, 2, 3]);',
'assertions' => [
'$d' => 'array{0: string, 1: string, 2: string, 3: int, 4: int, 5: int}',
'$d' => 'array{0: int, 1: int, 2: int, 3: string}',
],
],
'arrayReplacePossiblyUndefined' => [