mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Improve handling of coerced-to-array strings in array_splice
This commit is contained in:
parent
cb63f4f70f
commit
366f625c83
@ -391,6 +391,16 @@ class CallChecker
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($replacement_arg->inferredType)
|
||||
&& !$replacement_arg->inferredType->hasArray()
|
||||
&& $replacement_arg->inferredType->hasString()
|
||||
&& $replacement_arg->inferredType->isSingle()
|
||||
) {
|
||||
$replacement_arg->inferredType = new Type\Union([
|
||||
new Type\Atomic\TArray([Type::getInt(), $replacement_arg->inferredType])
|
||||
]);
|
||||
}
|
||||
|
||||
if (isset($array_arg->inferredType)
|
||||
&& $array_arg->inferredType->hasArray()
|
||||
&& isset($replacement_arg->inferredType)
|
||||
@ -419,8 +429,18 @@ class CallChecker
|
||||
$context,
|
||||
false
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
ExpressionChecker::assignByRefParam(
|
||||
$statements_checker,
|
||||
$array_arg,
|
||||
Type::getArray(),
|
||||
$context,
|
||||
false
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -920,6 +920,14 @@ class FunctionCallTest extends TestCase
|
||||
'$c' => 'array{0:int, 1:int, 2:int}',
|
||||
],
|
||||
],
|
||||
'arraySpliceOtherType' => [
|
||||
'<?php
|
||||
$d = [["red"], ["green"], ["blue"]];
|
||||
array_splice($d, -1, 1, "foo");',
|
||||
'assertions' => [
|
||||
'$d' => 'array<int, array{0:string}|string>',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user