[NodeTypeResolver] Use Scope->getType() on ArrayDimFetch on NodeTypeResolver::getNativeType()#5037
[NodeTypeResolver] Use Scope->getType() on ArrayDimFetch on NodeTypeResolver::getNativeType()#5037TomasVotruba merged 5 commits intomainfrom
Conversation
…esolver::getNativeType()
|
Please add tests which show why this is required |
|
The test case already exists |
|
All checks have passed 🎉 @TomasVotruba it is ready for review. |
| /** | ||
| * @param array{host: string} $parts | ||
| */ | ||
| public function checkUrl(array $parts) |
There was a problem hiding this comment.
@staabm the specific type of $parts['host'] from docblock will be detected as host: StringType instead of MixedType
that can be feature or bug :)
There was a problem hiding this comment.
if the shape was returned by a native extension, I would say its a feature.
if the shape is declared as a phpdoc, I would say its a bug :)
There was a problem hiding this comment.
how to detect if it is from native extension ?
There was a problem hiding this comment.
I think we can't detect it. but maybe we can enhance our own getNativeType() method to apply the phpstan-src native extensions (if thats not the case already).
|
For summary,
|
Are you sure this problem is related to ArrayDimFetch alone and not return type extensions or array-shapes or similar? |
|
There is no docblock definition on |
We may follow only phpdocs which can be validated by the lie detector https://phpstan.org/blog/phpstan-1-10-comes-with-lie-detector |
|
Most of use cases, when user define /** @param string[] $param */
function foo(array $param)
{
var_dump($param[0]); // string...
}instead of collection of mixed |
|
Thank you 🙏 |
|
after applying rector-dev on our codebase we run about all the issues I mentioned above. I think we need to revert it, because atm this PR does apply phpdoc-based array-shape type (if it would/could only apply array-shape types coming from phpstan native extensions it would be fine) see |
|
If we can check what variable came from, eg from assign to native function, I think we can get win win solution |
|
yeah, my main motivation is making sure this doesn't get into a release in the form it is right now. if we can improve/iterate on it, even better. |
|
see #5056 |
@staabm this is what I mean for using
Scope->getType()onArrayDimFetch, as usinggetNativeType()will got mixed on this code:checking with
getNativeType()always gotMixedTypeon$parts['host']which always string bygetType(), see fixture:rector-src/tests/Issues/EmptyBooleanCompare/Fixture/fixture.php.inc
Lines 3 to 37 in 8ba3d90