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 of known shapes loses type information #5846
Comments
Its a know problem. I guess a issue is already filled somewhere. Last time we tried to inprove this case we had to revert because the analysis was that time-intensive that it was not acceptable - phpstan/phpstan-src#622 (comment) |
There is already a new pull request that (at least in my tests) do not have the performance issue and still fix the |
fixed by phpstan/phpstan-src#1135 |
@Firehed After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-15: Dumped type: non-empty-array<literal-string&non-empty-string, int|string>
-16: Parameter #1 $s of function useString expects string, int|string given.
-17: Parameter #1 $i of function useInt expects int, int|string given.
+15: Dumped type: array{a: int, b: string} Full report
|
@Firehed After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
7: Dumped type: array{a: 1, b: 'bee'}
- 8: Dumped type: non-empty-array<literal-string&non-empty-string, 1|'bee'>
- 9: Parameter #1 $s of function useString expects string, int|string given.
-10: Parameter #1 $i of function useInt expects int, int|string given.
+ 8: Dumped type: array{a: 1, b: 'bee'} Full report
|
Needs a regression test :) /cc @VincentLanglet |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug report
Performing an
array_merge
where two arrays share a known shape results in type loss of the result.Code snippet that reproduces the problem
Original issue:
https://phpstan.org/r/bc48b3cb-e1f4-4b4a-81ca-d18bf8901104
Simplest form:
https://phpstan.org/r/34b0de0f-a3b6-4ed5-b802-ff500ebbb619
Expected output
No errors, dumpType shows:
The text was updated successfully, but these errors were encountered: