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

Arrow closure param type hint is ignored #4681

Closed
simPod opened this issue Mar 10, 2021 · 5 comments
Closed

Arrow closure param type hint is ignored #4681

simPod opened this issue Mar 10, 2021 · 5 comments

Comments

@simPod
Copy link
Contributor

simPod commented Mar 10, 2021

Bug report

I'm typing the arrow closure as

/** @param array{a: int} $row */
static fn (array $row) : A => new A($row),

Though PHPStan says I'm passing array into A, not array{a: int}.

Code snippet that reproduces the problem

https://phpstan.org/r/1784556f-11c5-4874-984f-18b654932da5

@ondrejmirtes
Copy link
Member

Linking with #3770 and #3660

@phpstan-bot
Copy link
Contributor

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

@@ @@
 
 14: Parameter #1 $row of class A constructor expects array('a' => int), array given.
 
-PHP 7.4 (2 errors)
+PHP 7.4 (1 error)
 ==========
 
- 5: Promoted properties are supported only on PHP 8.0 and later.
-14: Parameter #1 $row of class A constructor expects array('a' => int), array given.
+-1: Internal error: Property $row was not found in reflection of class A.
+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 (3 errors)
 ==========
Full report

PHP 8.0 (1 error)

Line Error
14 Parameter #1 $row of class A constructor expects array('a' => int), array given.

PHP 7.4 (1 error)

Line Error
-1 Internal error: Property $row was not found in reflection of class A.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 (3 errors)

Line Error
14 Syntax error, unexpected ',' on line 14
14 Syntax error, unexpected T_STRING, expecting T_PAAMAYIM_NEKUDOTAYIM on line 14
14 Syntax error, unexpected T_VARIABLE, expecting ':' on line 14

@phpstan-bot
Copy link
Contributor

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

@@ @@
-PHP 8.0 (1 error)
+PHP 8.0
 ==========
 
-14: Parameter #1 $row of class A constructor expects array('a' => int), array given.
+No errors
 
-PHP 7.4 (2 errors)
+PHP 7.4 (1 error)
 ==========
 
  5: Promoted properties are supported only on PHP 8.0 and later.
-14: Parameter #1 $row of class A constructor expects array('a' => int), array given.
 
 PHP 7.1 – 7.3 (3 errors)
 ==========
Full report

PHP 8.0

No errors

PHP 7.4 (1 error)

Line Error
5 Promoted properties are supported only on PHP 8.0 and later.

PHP 7.1 – 7.3 (3 errors)

Line Error
14 Syntax error, unexpected ',' on line 14
14 Syntax error, unexpected T_STRING, expecting T_PAAMAYIM_NEKUDOTAYIM on line 14
14 Syntax error, unexpected T_VARIABLE, expecting ':' on line 14

@simPod
Copy link
Contributor Author

simPod commented Jun 26, 2021 via email

@github-actions
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 Jul 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants