1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-11 16:59:45 +01:00

pass the method_id to be able to set the new offset type to 0 for array_unshift

This commit is contained in:
orklah 2021-10-07 09:46:49 +02:00
parent 6627055f3b
commit 3a2eddf2d7
2 changed files with 11 additions and 5 deletions

View File

@ -79,7 +79,7 @@ class ArgumentsAnalyzer
$statements_analyzer,
$args,
$context,
$method_id === 'array_push'
$method_id
) === false
) {
return false;

View File

@ -128,7 +128,7 @@ class ArrayFunctionArgumentsAnalyzer
StatementsAnalyzer $statements_analyzer,
array $args,
Context $context,
bool $is_push
string $method_id
): ?bool {
$array_arg = $args[0]->value;
@ -139,7 +139,7 @@ class ArrayFunctionArgumentsAnalyzer
}
);
if ($is_push && !$unpacked_args) {
if ($method_id === 'array_push' && !$unpacked_args) {
for ($i = 1, $iMax = count($args); $i < $iMax; $i++) {
$was_inside_assignment = $context->inside_assignment;
@ -239,12 +239,18 @@ class ArrayFunctionArgumentsAnalyzer
return false;
}
if ($method_id === 'array_unshift') {
$new_offset_type = Type::getInt(false, 0);
} else {
$new_offset_type = Type::getInt();
}
if (!($arg_value_type = $statements_analyzer->node_data->getType($arg->value))
|| $arg_value_type->hasMixed()
) {
$by_ref_type = Type::combineUnionTypes(
$by_ref_type,
new Type\Union([new TArray([Type::getInt(), Type::getMixed()])])
new Type\Union([new TArray([$new_offset_type, Type::getMixed()])])
);
} elseif ($arg->unpack) {
$arg_value_type = clone $arg_value_type;
@ -292,7 +298,7 @@ class ArrayFunctionArgumentsAnalyzer
[
new TNonEmptyArray(
[
Type::getInt(),
$new_offset_type,
clone $arg_value_type
]
),