-
Notifications
You must be signed in to change notification settings - Fork 494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix return type of parent calls for SplHeap #2622
fix return type of parent calls for SplHeap #2622
Conversation
patches/Memcache.patch
Outdated
* The lowest byte of the int is reserved for pecl/memcache internal usage (e.g. to indicate | ||
* compression and serialization status). | ||
* </p> | ||
- * @return string|array|false <p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This broke memcache-get.php
test. The explanation is here: #2323 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not (easily) possible to fix via functionMap.php
. There are two variants in function map: one which returns mixed
and one which returns array|false
. And as you can see, the phpdoc return type in phpstorm-stubs is string|array|false
.
decideType(mixed, string|array|false) = string|array|false
, which doesn't seem like something that could be changed.
Perhaps if decideType
also considered where the two types come from. E.g. in this case we know that the first type comes from the function map. Since string|array|false
could have been used in the function map, we could reach the conclusion that we used the broader type intentionally. However, there are issues in the function map as well, so it's though to say whether such approach would be more feasible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about disregarding PhpStorm stubs type completely if functionMap has multiple variants? But the "golden test" for Reflection will come in handy in that scenario :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, that worked (for memcace::get). I limited it specifically to the return type. The stubs are still useful/necessary for positional parameter names, @throws
, ...
But unfortunately, it doesn't cover the ReflectionPropety
patch.
1dfb4a5
to
1da5ae9
Compare
I'm gonna take a look at this soon but can you please look at this? phpstan/phpstan#9849 (reply in thread) I list two very common and very annoying issues, they're somewhat in the same area as this bug, and I think you're more than capable of addressing them 😊 Thank you very much. |
f94288a
to
13c5f34
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we solve this a different way instead of patching jetbrains/phpstorm-stubs? Like adding some entries to functionMap.php? Thanks!
Note to self: This might also get affected/fixed: phpstan/phpstan#10057
https://github.com/schlndh/phpstan-src/actions/runs/6586745404/job/17895674524?pr=1 |
13c5f34
to
f54bcec
Compare
I removed two of the patches (the SplHeap patch was accepted to upstream, and Memcache was fixed by your idea). I checked the differences in the reflection golden test - they seem mostly OK (though a lot of them are in niche, undocumented functions/methods, so I can't be 100% sure). Here are some of the wrong changes that I noticed:
It seems that these methods can return
There are several cases like this. The problem is this:
I guess this should be just |
This pull request has been marked as ready for review. |
As for the Mongo There's some logic in phpstan/phpdoc-parser that should avoid this problem: https://github.com/phpstan/phpdoc-parser/blob/c2b8bbfa971e25976e9c64ea30a4e944e2688cb4/src/Parser/TypeParser.php#L367-L395 Can you please try to write a failing test in the repository and maybe modify the logic so that it works for Mongo PHPDocs too? Thanks. |
0143307
to
aa6f456
Compare
Thank you! |
This is an attempt to fix phpstan/phpstan#9867
The issue happened because the return type for
SplHeap
methods ignored the phpdoc (as you can see from the change the previous code only considered phpdoc from stubs). I discovered that similar code uses theTypehintHelper
in these situations, so I used it as well.But it broke a few tests due to benevolent unions in the
functionaMap.php
. So I added a workaround for it. I couldn't think of any issues, since I haven't found any code uses benevolent unions and which would need a phpdoc as well (e.g. due to generics).Previously, it worked for
SplMinHeap
because it took a different branch inPhpClassReflectionExtension::createMethod
:SplMinHeap
has the methods duplicated in phpstorm-stubs, the$declaringClassName
isSplMinHeap
.$this->signatureMapProvider->hasMethodSignature($declaringClassName, $methodReflection->getName())
returns false, because thefunctionMap.php
only has the methods forSplHeap
. Since this is the branch that contains the incorrect code, the issue was avoided forSplMinHeap
.SplMaxHeap
andSplHeap
the declaring class isSplHeap
(which is in thefunctionMap.php
) and thus the branch was taken and the issue happened.Here are a few tests that didn't work without the change to
TypehintHelper::decideType
(there were a few more):