Don't loose known offset-types in array_merge()#4554
Don't loose known offset-types in array_merge()#4554ondrejmirtes merged 15 commits intophpstan:2.1.xfrom
Conversation
|
This pull request has been marked as ready for review. |
| * @return ConstantStringType|ConstantIntegerType | ||
| */ | ||
| public function getOffsetType(): Type | ||
| public function getOffsetType(): ConstantStringType|ConstantIntegerType |
There was a problem hiding this comment.
analog HasOffsetValueType->getOffsetType()
|
I like this 👍 Before looking at the code I thought I'd solve this with HasOffsetValueType as well. |
ondrejmirtes
left a comment
There was a problem hiding this comment.
Please do HasOffsetValueType instead in all cases, the result will be more precise.
This is not correct for int keys, as those will be renumbered. (This is the reason |
|
@claudepache thanks - I also realized it. Adjusted the PR accordingly, please have another look |
|
This pull request has been marked as ready for review. |
896cc33 to
87c3cb2
Compare
|
Could it solve phpstan/phpstan#13805 ? |
there is no |
18a66b8 to
caa4f14
Compare
|
Looking at this I think we should add This would ease building logic on top of it without the need for checking individual type classes |
6e895ea to
01d73f5
Compare
|
Thank you! |
the result of
array_mergewill always contain allstringkeys we see along the way.we can't reason about the values when not all arrays are constant, but we can remember the keys.since string keys overwrite each other, we know the value of the last string keys in the chain.
of other string based offsets we at least know about their existance.
best reviewed with whitespaces ignored
Followup could be doing the same for
+operator when merging arraysarray_replace