Skip to content

Fix array types after array_splice()#4844

Closed
takaram wants to merge 2 commits intophpstan:2.1.xfrom
takaram:bug-14037
Closed

Fix array types after array_splice()#4844
takaram wants to merge 2 commits intophpstan:2.1.xfrom
takaram:bug-14037

Conversation

@takaram
Copy link
Contributor

@takaram takaram commented Feb 1, 2026

*/
function splice(array $a): void {
array_splice($a, 0, 0);
assertType("array<'a'|int<0, max>, mixed>", $a);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be 'a'|int<0, 2>

You're doing $keyType = IntegerRangeType::createAllGreaterThanOrEqualTo(0);

but maybe you should check getConstantScalarTypes.
and if if (count($constantScalars) > 0), you're doing $keyType = IntegerRangeType::fromInterval(0, $count -1); ?

@VincentLanglet
Copy link
Contributor

Thanks, I merged your PR with #5139 which provides a slight better fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

array_splice resets int keys of the input array

2 participants