-
-
Notifications
You must be signed in to change notification settings - Fork 863
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
Cannot resolve template parameters of empty array #5065
Comments
@AlexandruGG After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-PHP 7.4 – 8.0 (1 error)
+PHP 7.4 – 8.0 (2 errors)
==========
+12: Property Collection::$source is never read, only written.
30: Method Collection::empty() should return Collection<NewTKey of (int|string), NewT> but returns Collection<*NEVER*, *NEVER*>.
PHP 7.1 – 7.3 (6 errors) Full reportPHP 7.4 – 8.0 (2 errors)
PHP 7.1 – 7.3 (6 errors)
|
@AlexandruGG After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-PHP 7.4 – 8.0 (1 error)
+PHP 7.4 – 8.0 (2 errors)
==========
+12: Property Collection::$source is never read, only written.
30: Method Collection::empty() should return Collection<NewTKey of (int|string), NewT> but returns Collection<*NEVER*, *NEVER*>.
PHP 7.1 – 7.3 (6 errors) Full reportPHP 7.4 – 8.0 (2 errors)
PHP 7.1 – 7.3 (6 errors)
|
@AlexandruGG After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-PHP 7.4 – 8.0 (1 error)
+PHP 7.4 – 8.0 (8 errors)
==========
+12: Property Collection::$source is never read, only written.
+28: Template type NewT of method Collection::empty() is not referenced in a parameter.
+28: Template type NewTKey of method Collection::empty() is not referenced in a parameter.
30: Method Collection::empty() should return Collection<NewTKey of (int|string), NewT> but returns Collection<*NEVER*, *NEVER*>.
+39: Template type NewT of method Collection::emptyWorkaround() is not referenced in a parameter.
+39: Template type NewTKey of method Collection::emptyWorkaround() is not referenced in a parameter.
+53: Template type NewT of method Collection::emptyWorkaround2() is not referenced in a parameter.
+53: Template type NewTKey of method Collection::emptyWorkaround2() is not referenced in a parameter.
PHP 7.1 – 7.3 (6 errors)
========== Full reportPHP 7.4 – 8.0 (8 errors)
PHP 7.1 – 7.3 (6 errors)
|
@AlexandruGG After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
PHP 7.4 – 8.0 (1 error)
==========
-30: Method Collection::empty() should return Collection<NewTKey of (int|string), NewT> but returns Collection<*NEVER*, *NEVER*>.
+-1: Internal error: PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule::findMethod(): Argument #2 ($classReflection) must be of type PHPStan\Reflection\ClassReflection, null given, called in /var/task/vendor/phpstan/phpstan-strict-rules/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php on line 40
+Run PHPStan with --debug option and post the stack trace to:
+https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md
PHP 7.1 – 7.3 (6 errors)
========== Full reportPHP 7.4 – 8.0 (1 error)
PHP 7.1 – 7.3 (6 errors)
|
@AlexandruGG After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-PHP 7.4 – 8.0 (1 error)
+PHP 7.4 – 8.0 (8 errors)
==========
+28: Template type NewTKey of method Collection::empty() is not referenced in a parameter.
+28: Template type NewT of method Collection::empty() is not referenced in a parameter.
30: Method Collection::empty() should return Collection<NewTKey of (int|string), NewT> but returns Collection<*NEVER*, *NEVER*>.
+39: Template type NewTKey of method Collection::emptyWorkaround() is not referenced in a parameter.
+39: Template type NewT of method Collection::emptyWorkaround() is not referenced in a parameter.
+53: Template type NewTKey of method Collection::emptyWorkaround2() is not referenced in a parameter.
+53: Template type NewT of method Collection::emptyWorkaround2() is not referenced in a parameter.
+12: Property Collection::$source is never read, only written.
PHP 7.1 – 7.3 (6 errors)
==========
+30: Syntax error, unexpected T_STRING, expecting T_PAAMAYIM_NEKUDOTAYIM on line 30
30: Syntax error, unexpected ':' on line 30
-30: Syntax error, unexpected T_STRING, expecting T_PAAMAYIM_NEKUDOTAYIM on line 30
+44: Syntax error, unexpected T_STRING, expecting T_PAAMAYIM_NEKUDOTAYIM on line 44
44: Syntax error, unexpected T_DOUBLE_ARROW on line 44
-44: Syntax error, unexpected T_STRING, expecting T_PAAMAYIM_NEKUDOTAYIM on line 44
-56: Syntax error, unexpected ':' on line 56
-56: Syntax error, unexpected T_STRING, expecting T_PAAMAYIM_NEKUDOTAYIM on line 56
+56: Syntax error, unexpected T_STRING, expecting T_PAAMAYIM_NEKUDOTAYIM on line 56
+56: Syntax error, unexpected ':' on line 56 Full reportPHP 7.4 – 8.0 (8 errors)
PHP 7.1 – 7.3 (6 errors)
|
I have to admit that revisiting the code-snippets after each PHPStan new commit, and displaying a comment when the result is different from previous one is a genius idea ! Congrats for this feature !!! |
@AlexandruGG After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-PHP 7.4 – 8.0 (1 error)
+PHP 7.4 – 8.0 (7 errors)
==========
-30: Method Collection::empty() should return Collection<NewTKey of (int|string), NewT> but returns Collection<*NEVER*, *NEVER*>.
+12: Property Collection::$source is never read, only written.
+28: Template type NewT of method Collection::empty() is not referenced in a parameter.
+28: Template type NewTKey of method Collection::empty() is not referenced in a parameter.
+39: Template type NewT of method Collection::emptyWorkaround() is not referenced in a parameter.
+39: Template type NewTKey of method Collection::emptyWorkaround() is not referenced in a parameter.
+53: Template type NewT of method Collection::emptyWorkaround2() is not referenced in a parameter.
+53: Template type NewTKey of method Collection::emptyWorkaround2() is not referenced in a parameter.
PHP 7.1 – 7.3 (6 errors)
========== Full reportPHP 7.4 – 8.0 (7 errors)
PHP 7.1 – 7.3 (6 errors)
|
Fixed: phpstan/phpstan-src@c2b9e71 |
Cool ! Thanks @ondrejmirtes ! Looking forward to test this in the next release. |
Closes phpstan/phpstan#5757 Closes phpstan/phpstan#5065 Closes phpstan/phpstan#3400 Closes phpstan/phpstan#6353
Nice one, thank you very much 🚀 |
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
When using an empty array in a place with template parameters, PHPStan seems to not be able to resolve the needed types, assigning type
*NEVER*
to the types of keys and values.Code snippet that reproduces the problem
https://phpstan.org/r/1f55bae3-c09d-49b0-be85-3f6a28e08dae
Expected output
I am not 100% sure if this is intended behaviour, please let me know if this is not a genuine bug. 🐛
I've included a couple "workarounds" that can be used to fix the error, but I'm not sure if they should be needed or not.
The same code in Psalm does not show an error: https://psalm.dev/r/0775d2d6b0
The text was updated successfully, but these errors were encountered: