-
-
Notifications
You must be signed in to change notification settings - Fork 918
Array reduce not understanding callback return with generics #8071
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
Comments
@BackEndTea After the latest push in 1.9.x, PHPStan now reports different result with your code snippet: @@ @@
-PHP 8.0 – 8.2 (1 error)
+PHP 8.0 – 8.2
==========
-18: Method Inheritance::inherit() should return array<TKey of (int|string), TValues of bool|float|int|string|null> but returns array<string>.
+No errors
-PHP 7.1 – 7.4 (2 errors)
+PHP 7.1 – 7.4 (1 error)
==========
-18: Method Inheritance::inherit() should return array<TKey of (int|string), TValues of bool|float|int|string|null> but returns array<string>.
33: Method Inheritance::callBack() uses native union types but they're supported only on PHP 8.0 and later. Full reportPHP 8.0 – 8.2No errors PHP 7.1 – 7.4 (1 error)
|
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. |
This issue was never fixed, but merely silenced... |
@BackEndTea After the latest push in 2.0.x, PHPStan now reports different result with your code snippet: @@ @@
18: Method Inheritance::inherit() should return array<TKey of (int|string), TValues of bool|float|int|string|null> but returns array<string>.
-PHP 7.1 – 7.4 (2 errors)
+PHP 7.1 – 7.4 (9 errors)
==========
18: Method Inheritance::inherit() should return array<TKey of (int|string), TValues of bool|float|int|string|null> but returns array<string>.
-33: Method Inheritance::callBack() uses native union types but they're supported only on PHP 8.0 and later.
+33: Method Inheritance::callBack() has parameter $carry with no value type specified in iterable type array.
+33: Method Inheritance::callBack() uses native union types but they're supported only on PHP 8.0 and later.
+33: PHPDoc tag @param for parameter $carry with type array<TKey of (int|string), TValues of bool|float|int|string|null>|null is not subtype of native type array|null.
+33: Parameter $carry of method Inheritance::callBack() has invalid type null.
+35: Strict comparison using === between array|null and null will always evaluate to false.
+39: Argument of an invalid type array|null supplied for foreach, only iterables are supported.
+44: Cannot access offset (int|string) on array|null.
+47: Method Inheritance::callBack() should return array<TKey of (int|string), TValues of bool|float|int|string|null> but returns array|null. Full reportPHP 8.0 – 8.2 (1 error)
PHP 7.1 – 7.4 (9 errors)
|
@BackEndTea After the latest push in 2.1.x, PHPStan now reports different result with your code snippet: @@ @@
-PHP 8.0 – 8.2 (1 error)
+PHP 8.0 – 8.2 (2 errors)
==========
18: Method Inheritance::inherit() should return array<TKey of (int|string), TValues of bool|float|int|string|null> but returns array<string>.
+33: Static method Inheritance::callBack() is unused.
-PHP 7.1 – 7.4 (2 errors)
+PHP 7.1 – 7.4 (10 errors)
==========
18: Method Inheritance::inherit() should return array<TKey of (int|string), TValues of bool|float|int|string|null> but returns array<string>.
-33: Method Inheritance::callBack() uses native union types but they're supported only on PHP 8.0 and later.
+33: Method Inheritance::callBack() has parameter $carry with no value type specified in iterable type array.
+33: Method Inheritance::callBack() uses native union types but they're supported only on PHP 8.0 and later.
+33: PHPDoc tag @param for parameter $carry with type array<TKey of (int|string), TValues of bool|float|int|string|null>|null is not subtype of native type array|null.
+33: Parameter $carry of method Inheritance::callBack() has invalid type null.
+33: Static method Inheritance::callBack() is unused.
+35: Strict comparison using === between array|null and null will always evaluate to false.
+39: Argument of an invalid type array|null supplied for foreach, only iterables are supported.
+44: Cannot access offset (int|string) on array|null.
+47: Method Inheritance::callBack() should return array<TKey of (int|string), TValues of bool|float|int|string|null> but returns array|null. Full reportPHP 8.0 – 8.2 (2 errors)
PHP 7.1 – 7.4 (10 errors)
|
@BackEndTea After the latest push in 2.1.x, PHPStan now reports different result with your code snippet: @@ @@
18: Method Inheritance::inherit() should return array<TKey of (int|string), TValues of bool|float|int|string|null> but returns array<string>.
-PHP 7.1 – 7.4 (2 errors)
+PHP 7.1 – 7.4 (8 errors)
==========
18: Method Inheritance::inherit() should return array<TKey of (int|string), TValues of bool|float|int|string|null> but returns array<string>.
-33: Method Inheritance::callBack() uses native union types but they're supported only on PHP 8.0 and later.
+33: Method Inheritance::callBack() uses native union types but they're supported only on PHP 8.0 and later.
+33: PHPDoc tag @param for parameter $carry with type array<TKey of (int|string), TValues of bool|float|int|string|null>|null is not subtype of native type array|null.
+33: Parameter $carry of method Inheritance::callBack() has invalid type null.
+35: Strict comparison using === between array<TKey of (int|string), TValues of bool|float|int|string|null>|null and null will always evaluate to false.
+39: Argument of an invalid type array<TKey of (int|string), TValues of bool|float|int|string|null>|null supplied for foreach, only iterables are supported.
+44: Cannot access offset TKey of (int|string) on array<TKey of (int|string), TValues of bool|float|int|string|null>|null.
+47: Method Inheritance::callBack() should return array<TKey of (int|string), TValues of bool|float|int|string|null> but returns array<TKey of (int|string), TValues of bool|float|int|string|null>|null. Full reportPHP 8.0 – 8.2 (1 error)
PHP 7.1 – 7.4 (8 errors)
|
Bug report
It seems
array_reduce
doesn't completely understand the return from the generics.Code snippet that reproduces the problem
https://phpstan.org/r/e5bcd1ac-83f1-485a-98cd-0d11d1c3386f
Expected output
I expected no errors here
The text was updated successfully, but these errors were encountered: