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
False positive with array_merge #2567
Comments
ArrayMergeFunctionDynamicReturnTypeExtension does not preserve ConstantArrayType. Feel free to send a fix. |
Note for anyone willing to work on this, (might be me in the future, who knows): ConstantArrayType is a subtype of what ArrayMergeFunctionDynamicReturnTypeExtension::getTypeFromFunctionCall I think new test data should be added to |
Here is a failing test case: https://github.com/phpstan/phpstan-src/compare/master...greg0ire:preserve-constant-array-type?expand=1 |
Is this a dup of #1516 ? |
@MarioLipinski PHPStan now reports different result with your code snippet: @@ @@
+PHP 7.3 – 8.0 (1 error)
+==========
+
+10: Parameter #1 $a of function foo expects array('foo' => string), array<string, ''> given.
+
+PHP 7.2 (1 error)
+==========
+
+ 6: Function foo() has parameter $a with no value type specified in iterable type array.
+
+PHP 7.1 (1 error)
+==========
+
10: Parameter #1 $a of function foo expects array('foo' => string), array<string, ''> given. Full reportPHP 7.3 – 8.0 (1 error)
PHP 7.2 (1 error)
PHP 7.1 (1 error)
|
@MarioLipinski After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-10: Parameter #1 $a of function foo expects array('foo' => string), array<string, ''> given.
+10: Parameter #1 $a of function foo expects array('foo' => string), array<non-empty-string, ''> given. Full report
|
@MarioLipinski After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-10: Parameter #1 $a of function foo expects array('foo' => string), array<string, ''> given.
+10: Parameter #1 $a of function foo expects array('foo' => string), array<non-empty-string, ''>&nonEmpty given. Full report
|
@MarioLipinski After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-10: Parameter #1 $a of function foo expects array('foo' => string), array<string, ''> given.
+No errors |
Fixed by: phpstan/phpstan-src#622 |
Unfortunately I had to revert this extension: phpstan/phpstan-src@53817aa It's because of performance impact on real-world projects. The extension itself may not be the fault but it proves that having more ConstantArrayType instances during analysis leads to a slowdown. The only way I see is to build a benchmarking mode into PHPStan itself that would compare the analysis times of project files and point out which file slowed down after this commit. Then isolate what exactly in that file causes it and try to optimize that. Unfortunately it's not my priority right now. |
@MarioLipinski After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-10: Parameter #1 $a of function foo expects array('foo' => string), array<string, ''> given.
+10: Parameter #1 $a of function foo expects array('foo' => string), array<literal-string&non-empty-string, ''>&nonEmpty given. Full report
|
@MarioLipinski After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-10: Parameter #1 $a of function foo expects array('foo' => string), array<string, ''> given.
+10: Parameter #1 $a of function foo expects array('foo' => string), non-empty-array<literal-string&non-empty-string, ''> given. Full report
|
@MarioLipinski After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-10: Parameter #1 $a of function foo expects array('foo' => string), array<string, ''> given.
+10: Parameter #1 $a of function foo expects array{foo: string}, non-empty-array<literal-string&non-empty-string, ''> given. Full report
|
fixed by phpstan/phpstan-src#1135 |
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. |
I am getting a "Property ... (array<string, bool|int|string>) does not accept array<string, int>" error when working with array_merge().
https://phpstan.org/r/82e6d926-5634-4f25-ab61-c08cf403582b
I would expect to not get such an error when each of the passed associative arrays should work.
The text was updated successfully, but these errors were encountered: