-
Notifications
You must be signed in to change notification settings - Fork 506
non-empty-array<mixed> does not accept array with hasOffsetValue #3924
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
Conversation
This pull request has been marked as ready for review. |
I see we have more todo here. a union of 2 non-empty-arrays with has-offset accessory atm is just https://phpstan.org/r/cfad9fa9-2279-4f97-b9df-580aab7aa844 edit: fixed in #3937 |
@@ -122,6 +122,10 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult | |||
|
|||
public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult | |||
{ | |||
if ($acceptingType->isArray()->yes() && $acceptingType->isIterableAtLeastOnce()->yes()) { | |||
return AcceptsResult::createYes(); |
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.
It should check the iterable value type against $this->valueType
.
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.
I can't check the iteratable-value-type and the non-emptiness in a single IF because $acceptingType
is invoked once for each element of the intersection.
this means I get the ArrayType
which I could check against the value-type, but not against non-emptiness
and on the 2nd call I get the NonEmptyArray
type, which I can check only against the non-emptiness, but not the value type
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.
I will think more about it.. maybe we need a fix directly on IntersectionType
then
ohh lol, I did not realize that my recently merged PR fixed the issue |
This pull request has been marked as ready for review. |
lets use this PR to just land the regression test. its fixed |
Thank you. |
BTW it'd still be beneficial to write some actual unit tests for the types in question, maybe we realize the fix is still needed for some situations where the types don't even go through |
closes phpstan/phpstan#12847
edit: the underlying issue was fixed with #3937