forked from vimeo/psalm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vimeo#4997 added more precise type inference for
count()
returning …
…`0` or `positive-int` on known arrays (vimeo#4999) * vimeo#4997 added more precise stub for `count()` returning `0` or `positive-int` on known types * vimeo#4997 updated `count()` to support `\SimpleXmlElement` and `\ResourceBundle` counting, as well as handling hardcoded 2-element-arrays cases This patch: * adds support for `count(\SimpleXmlElement)` (https://www.php.net/manual/en/simplexmlelement.count.php) * adds support for `count(\ResourceBundle)` (https://www.php.net/manual/en/resourcebundle.count.php) * removes usage of global constants from stub (not supported - see https://www.php.net/manual/en/function.count.php) * adds support for identifying fixed-element-count arrays, for example `count(callable&array)`, which is always `2` * vimeo#4997 adapted `FunctionCallReturnTypeFetcher` to infer `TPositiveInt` for `count(TNonEmptyArray)` and `count(TNonEmptyList)` * The `FunctionCallReturnTypeFetcher` is responsible for defining the precise type of a `\count(T)` expression when given a `T`, so we baked the whole type resolution for `positive-int`, `0` and `positive-int|0` directly in there. While this complicates things, it is also true that it is not possible right now (for the stubs) to provide the level of detail around `count()` that is required by the type inference system for such a complex function with so many different semantics.
- Loading branch information
Showing
2 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters