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

First-class closure return type not resolved correctly #11056

Closed
uuf6429 opened this issue May 18, 2024 · 4 comments
Closed

First-class closure return type not resolved correctly #11056

uuf6429 opened this issue May 18, 2024 · 4 comments
Labels
Milestone

Comments

@uuf6429
Copy link
Contributor

uuf6429 commented May 18, 2024

Bug report

The return type of generic first-class closures doesn't seem to resolve correctly.

Wrapping them in an arrow function or anonymous function seems to bypass the problem.

The type of closure (method, static method or function) doesn't seem to make a difference.

(discovered in #11055 (comment))

Code snippet that reproduces the problem

https://phpstan.org/r/3ac8de30-a9c4-4c59-b5eb-fe58291e30f5

Expected output

In the given example, no errors/warnings were expected to be reported in PHP 8.3.

Did PHPStan help you today? Did it make you happy in any way?

Yeah, managed to catch a couple of bugs that even testing didn't catch. 💪

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone May 18, 2024
@phpstan-bot
Copy link
Contributor

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

@@ @@
 32: Parameter #1 $values of function receive expects array<Item>, array<int, mixed> given.
 39: Parameter #1 $values of function receive expects array<Item>, array<int, T> given.
 
-PHP 7.4 – 8.0 (4 errors)
+PHP 7.2 – 8.0 (4 errors)
 ==========
 
 32: Parameter #1 $values of function receive expects array<Item>, array<int, mixed> given.
 33: First-class callables are supported only on PHP 8.1 and later.
 39: Parameter #1 $values of function receive expects array<Item>, array<int, T> given.
-40: First-class callables are supported only on PHP 8.1 and later.
-
-PHP 7.2 – 7.3 (8 errors)
-==========
-
-47: Syntax error, unexpected ',' on line 47
-47: Syntax error, unexpected T_DOUBLE_ARROW on line 47
-47: Syntax error, unexpected T_STRING, expecting T_PAAMAYIM_NEKUDOTAYIM on line 47
-49: Syntax error, unexpected ')' on line 49
-54: Syntax error, unexpected ',' on line 54
-54: Syntax error, unexpected T_DOUBLE_ARROW on line 54
-54: Syntax error, unexpected T_STRING, expecting T_PAAMAYIM_NEKUDOTAYIM on line 54
-56: Syntax error, unexpected ')' on line 56
+40: First-class callables are supported only on PHP 8.1 and later.
Full report

PHP 8.1 – 8.3 (2 errors)

Line Error
32 Parameter #1 $values of function receive expects array<Item>, array<int, mixed> given.
39 Parameter #1 $values of function receive expects array<Item>, array<int, T> given.

PHP 7.2 – 8.0 (4 errors)

Line Error
32 Parameter #1 $values of function receive expects array<Item>, array<int, mixed> given.
33 First-class callables are supported only on PHP 8.1 and later.
39 Parameter #1 $values of function receive expects array<Item>, array<int, T> given.
40 First-class callables are supported only on PHP 8.1 and later.

@phpstan-bot
Copy link
Contributor

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

@@ @@
-PHP 8.1 – 8.3 (2 errors)
+PHP 8.1 – 8.3
 ==========
 
-32: Parameter #1 $values of function receive expects array<Item>, array<int, mixed> given.
-39: Parameter #1 $values of function receive expects array<Item>, array<int, T> given.
+No errors
 
-PHP 7.4 – 8.0 (4 errors)
+PHP 7.2 – 8.0 (2 errors)
 ==========
 
-32: Parameter #1 $values of function receive expects array<Item>, array<int, mixed> given.
 33: First-class callables are supported only on PHP 8.1 and later.
-39: Parameter #1 $values of function receive expects array<Item>, array<int, T> given.
-40: First-class callables are supported only on PHP 8.1 and later.
-
-PHP 7.2 – 7.3 (8 errors)
-==========
-
-47: Syntax error, unexpected ',' on line 47
-47: Syntax error, unexpected T_DOUBLE_ARROW on line 47
-47: Syntax error, unexpected T_STRING, expecting T_PAAMAYIM_NEKUDOTAYIM on line 47
-49: Syntax error, unexpected ')' on line 49
-54: Syntax error, unexpected ',' on line 54
-54: Syntax error, unexpected T_DOUBLE_ARROW on line 54
-54: Syntax error, unexpected T_STRING, expecting T_PAAMAYIM_NEKUDOTAYIM on line 54
-56: Syntax error, unexpected ')' on line 56
+40: First-class callables are supported only on PHP 8.1 and later.
Full report

PHP 8.1 – 8.3

No errors

PHP 7.2 – 8.0 (2 errors)

Line Error
33 First-class callables are supported only on PHP 8.1 and later.
40 First-class callables are supported only on PHP 8.1 and later.

@ondrejmirtes
Copy link
Member

Fixed by phpstan/phpstan-src#3425

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 Oct 12, 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

3 participants