Skip to content
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

Generics - closure type inference bug #5508

Closed
ondrejmirtes opened this issue Aug 22, 2021 · 6 comments
Closed

Generics - closure type inference bug #5508

ondrejmirtes opened this issue Aug 22, 2021 · 6 comments
Labels
Milestone

Comments

@ondrejmirtes
Copy link
Member

Bug report

Code snippet that reproduces the problem

https://phpstan.org/r/15176d68-f91e-495d-8b23-437853a55392

Expected output

The resulting type should be array<int, string>

@ondrejmirtes ondrejmirtes added this to the Generics milestone Aug 22, 2021
@phpstan-bot
Copy link
Contributor

@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
 PHP 7.1 – 7.4 (3 errors)
 ==========
 
-37: Parameter #1 $items of class Collection constructor expects array<TMapValue>, array<TKey of (int|string), TMapValue>|false given.
+37: Parameter #1 $items of class Collection constructor expects array<TKey of (int|string), TMapValue>, array<TKey of (int|string), TMapValue>|false given.
 49: Anonymous function should have native return typehint "string".
 53: Expected type array<int, string>, actual: array<int, mixed>
Full report

PHP 8.0 (2 errors)

Line Error
49 Anonymous function should have native return typehint "string".
53 Expected type array<int, string>, actual: array<int, mixed>

PHP 7.1 – 7.4 (3 errors)

Line Error
37 `Parameter #1 $items of class Collection constructor expects array<TKey of (int
49 Anonymous function should have native return typehint "string".
53 Expected type array<int, string>, actual: array<int, mixed>

@phpstan-bot
Copy link
Contributor

@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-PHP 8.0 (2 errors)
+PHP 8.0 (3 errors)
 ==========
 
+35: Parameter #1 $callback of function array_map expects callable(TValue): mixed, callable(TValue, TKey of (int|string)): TMapValue given.
 49: Anonymous function should have native return typehint "string".
 53: Expected type array<int, string>, actual: array<int, mixed>
 
-PHP 7.1 – 7.4 (3 errors)
+PHP 7.1 – 7.4 (4 errors)
 ==========
 
-37: Parameter #1 $items of class Collection constructor expects array<TMapValue>, array<TKey of (int|string), TMapValue>|false given.
+35: Parameter #1 $callback of function array_map expects callable(TValue): mixed, callable(TValue, TKey of (int|string)): TMapValue given.
+37: Parameter #1 $items of class Collection constructor expects array<TKey of (int|string), TMapValue>, array<TKey of (int|string), TMapValue>|false given.
 49: Anonymous function should have native return typehint "string".
 53: Expected type array<int, string>, actual: array<int, mixed>
Full report

PHP 8.0 (3 errors)

Line Error
35 `Parameter #1 $callback of function array_map expects callable(TValue): mixed, callable(TValue, TKey of (int
49 Anonymous function should have native return typehint "string".
53 Expected type array<int, string>, actual: array<int, mixed>

PHP 7.1 – 7.4 (4 errors)

Line Error
35 `Parameter #1 $callback of function array_map expects callable(TValue): mixed, callable(TValue, TKey of (int
37 `Parameter #1 $items of class Collection constructor expects array<TKey of (int
49 Anonymous function should have native return typehint "string".
53 Expected type array<int, string>, actual: array<int, mixed>

@phpstan-bot
Copy link
Contributor

@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-PHP 8.0 (2 errors)
+PHP 8.0 (1 error)
 ==========
 
-49: Anonymous function should have native return typehint "string".
 53: Expected type array<int, string>, actual: array<int, mixed>
 
-PHP 7.1 – 7.4 (3 errors)
+PHP 7.1 – 7.4 (2 errors)
 ==========
 
-37: Parameter #1 $items of class Collection constructor expects array<TMapValue>, array<TKey of (int|string), TMapValue>|false given.
-49: Anonymous function should have native return typehint "string".
+37: Parameter #1 $items of class Collection constructor expects array<TKey of (int|string), TMapValue>, array<TKey of (int|string), TMapValue>|false given.
 53: Expected type array<int, string>, actual: array<int, mixed>
Full report

PHP 8.0 (1 error)

Line Error
53 Expected type array<int, string>, actual: array<int, mixed>

PHP 7.1 – 7.4 (2 errors)

Line Error
37 `Parameter #1 $items of class Collection constructor expects array<TKey of (int
53 Expected type array<int, string>, actual: array<int, mixed>

@phpstan-bot
Copy link
Contributor

@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-PHP 8.0 (2 errors)
-==========
-
-49: Anonymous function should have native return typehint "string".
-53: Expected type array<int, string>, actual: array<int, mixed>
-
-PHP 7.1 – 7.4 (3 errors)
-==========
-
-37: Parameter #1 $items of class Collection constructor expects array<TMapValue>, array<TKey of (int|string), TMapValue>|false given.
-49: Anonymous function should have native return typehint "string".
-53: Expected type array<int, string>, actual: array<int, mixed>
+-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
Full report
Line Error
-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 40Run PHPStan with --debug option and post the stack trace to:https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md

@phpstan-bot
Copy link
Contributor

@ondrejmirtes After the latest push in 1.11.x, PHPStan now reports different result with your code snippet:

@@ @@
-PHP 8.0 (2 errors)
+PHP 8.0
 ==========
 
-49: Anonymous function should have native return typehint "string".
-53: Expected type array<int, string>, actual: array<int, mixed>
+No errors
 
-PHP 7.1 – 7.4 (3 errors)
+PHP 7.1 – 7.4 (1 error)
 ==========
 
-37: Parameter #1 $items of class Collection constructor expects array<TMapValue>, array<TKey of (int|string), TMapValue>|false given.
-49: Anonymous function should have native return typehint "string".
-53: Expected type array<int, string>, actual: array<int, mixed>
+37: Parameter #1 $items of class Collection constructor expects array<TKey of (int|string), TMapValue>, array<TKey of (int|string), TMapValue>|false given.
Full report

PHP 8.0

No errors

PHP 7.1 – 7.4 (1 error)

Line Error
37 `Parameter #1 $items of class Collection constructor expects array<TKey of (int

Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants