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
array_merge lost non-empty-string keys type #1135
Conversation
unrelated: there is a interessting test-case, I tried to add.
it errors with
which is a different bug IMO.. but interessting nevertheless |
I agree, it shouldn't be generalized. |
the remaining error
seems legit and unrelated, because the code seems not to be dependent on |
@@ -4707,31 +4707,31 @@ public function dataArrayFunctions(): array | |||
'array_values($generalStringKeys)', | |||
], | |||
[ | |||
'non-empty-array<int|(literal-string&non-empty-string), stdClass>', | |||
'array{foo: stdClass, 1: stdClass}', |
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.
changed existing tests, to more specific types - as the PR gets better results in these cases.
* @param array{return: int, stdout: string, stderr: string} $params1 | ||
* @param array{return: int, stdout?: string, stderr?: string} $params2 |
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 test is inspired by a scenario which failed with a previous version of this PR within the composer code-base
$newArrayBuilder = ConstantArrayTypeBuilder::createEmpty(); | ||
foreach ($argTypes as $argType) { | ||
if (!$argType instanceof ConstantArrayType) { | ||
throw new ShouldNotHappenException(); |
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.
You could push only ConstantArrayType into $argTypes
and this condition would not be necessary :)
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.
but then I couldn't re-use the $artTypes
for the 2nd-foreach loop..?
or I have all non-constant-array-args to be resolved twice via scope->getType
or alternatively I need 2 arrays to hold the different args per type
Thank you, let's try this! |
The same thing that happened last time someone tried to do this happened again :( #641 (comment) This version is about 30 % slower on Slevomat's codebase than previous commit. I'm gonna revert this. Can you please send a new PR that just removes the generalization to see if it fixes the related issues? https://github.com/phpstan/phpstan-src/pull/1135/files#diff-235402991c12d4f1091a88a9c19ed82c38749ed4e4dce1322474ed6c6d7fdcc8L47-R92 |
Oh, previous commit is also slow, I overlooked it. Well, we have a rabbit hole to go through. |
Alright, it's the same speed as the last stable version, we can release this as it is. (It might have something to do I'm on battery right now, I'm used to seeing faster numbers though.) |
suggestion for a fix of bug #6927.
I am wondering why the
generalize
call was in theArrayMergeFunctionDynamicReturnTypeExtension
.. the only thing I could think of are "cosmetic" reasons for error messages, since the types we get when dropping the
generalize
call seem to be more precise and still valid? lets see what CI thinks about it.the
generalize
call was added a long time ago with 002aa73closes phpstan/phpstan#6927