Fix false positive comparing identical generic types below level 8 - #6392
Open
calebdw wants to merge 1 commit into
Open
Fix false positive comparing identical generic types below level 8#6392calebdw wants to merge 1 commit into
calebdw wants to merge 1 commit into
Conversation
calebdw
force-pushed
the
calebdw/push-vquvsktlxvyr
branch
from
September 8, 2026 13:02
8e07b4e to
8ac890b
Compare
ondrejmirtes
requested changes
Sep 8, 2026
calebdw
force-pushed
the
calebdw/push-vquvsktlxvyr
branch
3 times, most recently
from
September 9, 2026 16:59
c46303b to
bdcf4b8
Compare
Member
|
Please add regression tests for phpstan/phpstan#12008 and phpstan/phpstan#9377. |
Member
|
And add these issues to the "closes" lines. |
calebdw
force-pushed
the
calebdw/push-vquvsktlxvyr
branch
from
September 9, 2026 20:34
bdcf4b8 to
becfef4
Compare
Contributor
Author
|
@ondrejmirtes, done---and I added regression tests for the other issues as well |
RuleLevelHelper relaxes the nullability of the accepted type but not of the accepting one, which is what lets a nullable value be passed where a non-nullable one is expected below level 8. TypeTraverser applied that relaxation to generic type arguments as well, so the argument of an accepted Collection<string, int|null> became int while the accepting side kept int|null. Compared invariantly, two identical types then stopped matching and the reported message printed the same type on both sides. Skip the mapper on GenericObjectType and map its children via Type::traverse() instead, which also preserves subclasses through recreate().
calebdw
force-pushed
the
calebdw/push-vquvsktlxvyr
branch
from
September 9, 2026 20:37
becfef4 to
8947d4e
Compare
VincentLanglet
approved these changes
Sep 9, 2026
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.
Hello!
Closes phpstan/phpstan#13876
Closes phpstan/phpstan#12984
Closes phpstan/phpstan#12008
Closes phpstan/phpstan#11041
Closes phpstan/phpstan#10698
Closes phpstan/phpstan#9377
Closes phpstan/phpstan#9096
RuleLevelHelper relaxes the nullability of the accepted type but not of the accepting one, which is what lets a nullable value be passed where a non-nullable one is expected below level 8. TypeTraverser applied that relaxation to generic type arguments as well, so the argument of an accepted Collection<string, int|null> became int while the accepting side kept int|null. Compared invariantly, two identical types then stopped matching and the reported message printed the same type on both sides.
Map the arguments of a concrete generic type instead of feeding them through the relaxation. A template type keeps going through the regular traversal, as rebuilding it as a plain generic would lose its bound.
Thanks!