-
Notifications
You must be signed in to change notification settings - Fork 426
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
Add "DynamicFunctionReturnTypeExtension" for "array_replace" + fix for "array_merge" #696
Conversation
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.
How is this different to ArrayMergeFunctionDynamicReturnTypeExtension? Are they going to differ in the future?
$argType = $argType->getIterableValueType(); | ||
if ($argType instanceof UnionType) { | ||
foreach ($argType->getTypes() as $innerType) { | ||
$argType = $innerType; |
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 don't understand this part - the last inner type in the union will win in the $argType
variable?
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 know the same code is in ArrayMergeFunctionDynamicReturnTypeExtension - it also puzzles me there.
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 makes no sense to me. Maybe this https://github.com/phpstan/phpstan-src/pull/622/files#diff-2b90d7b4bf7114d779c5be8175b43e99ebb849c71781c4285c6cc47bb6cba5d3R40 is more correct?
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 don't know, you tell me :(
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.
:)
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.
In the last pull request we already tried to process every parameter. I could re-add it, so we can see if it works, but the performance was bad, so that I will not add anything related to array shapes, ok?
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.
Let's try and see what happens :)
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 re-added the fixes and added a limit for the array. I also added the fix for "array_merge" here, so we can see the differences between the implementations in one diff.
If we check the type of the key, then we could implement the correct behavior in the future. |
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.
Please add a regression test for phpstan/phpstan#5846 here and I'll take a look :) Thank you.
I re-added some changes, even more tests and added some checks to prevent performance issues, but maybe we need to adjust the consts "MAX_*" settings? I already tested the performance with a private project and blackfire.io and for me, it looks good, but as airways it depends on the tested code. |
+ try to prevent performance issues from it: maybe we need to adjust the consts "MAX_*"
ddd20b4
to
95d480b
Compare
This Extension is a copy of "ArrayMergeFunctionDynamicReturnTypeExtension"
⇾ requested here: #622
INFO: Currently we are getting wrong types from "ArrayMergeFunctionDynamicReturnTypeExtension" because PHP handles array-keys different here: https://3v4l.org/YfKYq