phpstan-src icon indicating copy to clipboard operation
phpstan-src copied to clipboard

Fix ArrayCountValuesDynamicReturnTypeExtension

Open VincentLanglet opened this issue 1 month ago • 4 comments

$type->toArrayKey() instanceof ErrorType is not the right check cause true, false, 1.0, null, ... are ignored by the function. It has to be an int or a string.

And numeric string wasn't casted into int when used as array key.

VincentLanglet avatar Dec 07 '25 14:12 VincentLanglet

Looks like it should be $allowedValues->isSuperTypeOf(...)

staabm avatar Dec 07 '25 14:12 staabm

Looks like it should be $allowedValues->isSuperTypeOf(...)

How you deal with something like "int|null" ? I dont see the benefit with keeping the unionType check and calling filterType on it rather than doing an intersection like I did.

VincentLanglet avatar Dec 07 '25 16:12 VincentLanglet

I see now, that you also need the normalized result. its not just a check for compatibility. my suggestion did not fit that.

staabm avatar Dec 07 '25 16:12 staabm

good catches, didn't think to try other scalar types :+1:

mad-briller avatar Dec 08 '25 10:12 mad-briller