infer non-empty-list/array after isset($arr[$i])#4441
Draft
staabm wants to merge 10 commits intophpstan:2.1.xfrom
Draft
infer non-empty-list/array after isset($arr[$i])#4441staabm wants to merge 10 commits intophpstan:2.1.xfrom
non-empty-list/array after isset($arr[$i])#4441staabm wants to merge 10 commits intophpstan:2.1.xfrom
Conversation
staabm
commented
Oct 15, 2025
src/Analyser/TypeSpecifier.php
Outdated
| $types = $types->unionWith( | ||
| $this->create( | ||
| $var->var, | ||
| new NonEmptyArrayType(), |
Contributor
Author
There was a problem hiding this comment.
hmm interessting.. for some reason this operation makes array loose their template type.
3) PHPStan\Rules\Methods\ReturnTypeRuleTest::testBug7511
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'
+'48: Method Bug7511\HelloWorld::computeForFrontByPosition() should return array<T of Bug7511\PositionEntityInterface&Bug7511\TgEntityInterface> but returns array<Bug7511\PositionEntityInterface&Bug7511\TgEntityInterface>.
'
/Users/m.staab/dvl/phpstan-src/src/Testing/RuleTestCase.php:179
/Users/m.staab/dvl/phpstan-src/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php:759
Contributor
Author
Contributor
Author
There was a problem hiding this comment.
@VincentLanglet do you have an idea how this works?
Contributor
Author
There was a problem hiding this comment.
@jiripudil may I ask you whether you can make sense of this new error, whether it is correct or how a fix can/should look like? my generics fuu is not enough to reason about the results of the above comments
0be85ea to
fe6216b
Compare
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.

analog #4440 but for
isset($arr[$i])closes phpstan/phpstan#13674