Repository navigation
Narrow the native type of an array that array_is_list() rejects from the native type - #7235
Merged
Merged
Conversation
…the native type The false branch of array_is_list() made the argument non-empty by intersecting its PHPDoc type with non-empty-array, and that sure type was applied to the native type too. A native array with a PHPDoc list type then became *NEVER*. Narrow both by non-empty-array alone instead. Amp-Thread-ID: https://ampcode.com/threads/T-01a22076-5e23-72be-a499-cc7242c24f93
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since 0143e40, the false branch of
array_is_list()intersected the argument's PHPDoc type withnon-empty-array. That sure type was applied to the native type as well, so withtreatPhpDocTypesAsCertain: false, a native?arraywith alist<object>|nullPHPDoc became*NEVER*and code in that branch reportedfunction.alreadyNarrowedType(seen in symfony'sControllerEvent::setController()).Both types are now narrowed by
non-empty-arrayalone, so each keeps its own key and value types.array{a?: string}still becomesarray{a: string}.MatchExpressionRuleTest::testBug8937now reports the native typenon-empty-arrayinstead ofnon-empty-array<string>: the parameter is nativelyarray|string, so<string>came from the PHPDoc.Closes phpstan/phpstan#15875
Amp thread: https://ampcode.com/threads/T-01a22076-5e23-72be-a499-cc7242c24f93