-
-
Notifications
You must be signed in to change notification settings - Fork 864
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
Callable parameter types aren't correctly inferred #3818
Comments
Return types seems to have the same limitation: |
@nreynis PHPStan now reports different result with your code snippet: @@ @@
==========
29: Else branch is unreachable because ternary operator condition is always true.
-34: Parameter #1 $immutableGenerator of class Test constructor expects callable(mixed): DateTimeImmutable, Closure(mixed): DateTimeImmutable|null given.
+35: Parameter #1 $immutableGenerator of class Test constructor expects callable(mixed): DateTimeImmutable, Closure(mixed): DateTimeImmutable|null given.
PHP 7.1 – 7.3 (4 errors)
========== Full reportPHP 7.4 – 8.0 (2 errors)
PHP 7.1 – 7.3 (4 errors)
|
@nreynis After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
==========
29: Else branch is unreachable because ternary operator condition is always true.
-34: Parameter #1 $immutableGenerator of class Test constructor expects callable(mixed): DateTimeImmutable, Closure(mixed): DateTimeImmutable|null given.
+35: Parameter #1 $immutableGenerator of class Test constructor expects callable(T): DateTimeImmutable, Closure(mixed): DateTimeImmutable|null given.
PHP 7.1 – 7.3 (4 errors)
========== Full reportPHP 7.4 – 8.0 (2 errors)
PHP 7.1 – 7.3 (4 errors)
|
@nreynis After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-PHP 7.4 – 8.0 (2 errors)
+PHP 7.4 – 8.0 (3 errors)
==========
+15: Property Test::$generator is never read, only written.
29: Else branch is unreachable because ternary operator condition is always true.
-34: Parameter #1 $immutableGenerator of class Test constructor expects callable(mixed): DateTimeImmutable, Closure(mixed): DateTimeImmutable|null given.
+35: Parameter #1 $immutableGenerator of class Test constructor expects callable(mixed): DateTimeImmutable, Closure(mixed): DateTimeImmutable|null given.
PHP 7.1 – 7.3 (4 errors)
========== Full reportPHP 7.4 – 8.0 (3 errors)
PHP 7.1 – 7.3 (4 errors)
|
@nreynis 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)
==========
+16: Property Test::$generator is never read, only written.
30: Else branch is unreachable because ternary operator condition is always true.
PHP 7.1 – 7.3 (4 errors) Full reportPHP 7.4 – 8.0 (2 errors)
PHP 7.1 – 7.3 (4 errors)
|
@nreynis After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-PHP 7.4 – 8.0 (2 errors)
+PHP 7.4 – 8.0 (3 errors)
==========
+15: Property Test::$generator is never read, only written.
29: Else branch is unreachable because ternary operator condition is always true.
-34: Parameter #1 $immutableGenerator of class Test constructor expects callable(mixed): DateTimeImmutable, Closure(mixed): DateTimeImmutable|null given.
+35: Parameter #1 $immutableGenerator of class Test constructor expects callable(mixed): DateTimeImmutable, Closure(mixed): DateTimeImmutable|null given.
PHP 7.1 – 7.3 (4 errors)
========== Full reportPHP 7.4 – 8.0 (3 errors)
PHP 7.1 – 7.3 (4 errors)
|
@nreynis 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)
==========
+16: Property Test::$generator is never read, only written.
30: Else branch is unreachable because ternary operator condition is always true.
PHP 7.1 – 7.3 (4 errors) Full reportPHP 7.4 – 8.0 (2 errors)
PHP 7.1 – 7.3 (4 errors)
|
Not sure if it's the exact same issue, but I found something that looks similar. https://phpstan.org/r/525c36eb-c861-45bf-85ca-0315555e923f Not sure how to fix this. |
@nreynis After the latest push in 1.11.x, PHPStan now reports different result with your code snippet: @@ @@
-PHP 7.4 – 8.0 (2 errors)
+PHP 7.4 – 8.0 (3 errors)
==========
+15: Property Test::$generator is never read, only written.
29: Else branch is unreachable because ternary operator condition is always true.
-34: Parameter #1 $immutableGenerator of class Test constructor expects callable(mixed): DateTimeImmutable, Closure(mixed): DateTimeImmutable|null given.
+35: Parameter #1 $immutableGenerator of class Test constructor expects callable(mixed): DateTimeImmutable, Closure(mixed): (DateTimeImmutable|null) given.
PHP 7.1 – 7.3 (4 errors)
========== Full reportPHP 7.4 – 8.0 (3 errors)
PHP 7.1 – 7.3 (4 errors)
|
@Einenlum After the latest push in 1.11.x, PHPStan now reports different result with your code snippet: @@ @@
-PHP 8.1 – 8.2 (1 error)
+PHP 8.1 – 8.2
==========
-17: Parameter #1 $a of callable (Closure(A): void)|(Closure(B): void) expects A, A|B given.
+No errors
-PHP 8.0 (3 errors)
+PHP 8.0 (2 errors)
==========
15: First-class callables are supported only on PHP 8.1 and later.
15: First-class callables are supported only on PHP 8.1 and later.
-17: Parameter #1 $a of callable (Closure(A): void)|(Closure(B): void) expects A, A|B given.
-PHP 7.2 – 7.4 (4 errors)
+PHP 7.2 – 7.4 (3 errors)
==========
13: Method Foo::handle() uses native union types but they're supported only on PHP 8.0 and later.
15: First-class callables are supported only on PHP 8.1 and later.
-15: First-class callables are supported only on PHP 8.1 and later.
-17: Parameter #1 $a of callable (Closure(A): void)|(Closure(B): void) expects A, A|B given.
+15: First-class callables are supported only on PHP 8.1 and later. Full reportPHP 8.1 – 8.2No errors PHP 8.0 (2 errors)
PHP 7.2 – 7.4 (3 errors)
|
@nreynis After the latest push in 1.11.x, PHPStan now reports different result with your code snippet: @@ @@
-PHP 7.4 – 8.0 (2 errors)
+PHP 7.4 – 8.0 (3 errors)
==========
+15: Property Test::$generator is never read, only written.
29: Else branch is unreachable because ternary operator condition is always true.
-34: Parameter #1 $immutableGenerator of class Test constructor expects callable(mixed): DateTimeImmutable, Closure(mixed): DateTimeImmutable|null given.
+35: Parameter #1 $immutableGenerator of class Test constructor expects callable(T): DateTimeImmutable, Closure(T): (DateTimeImmutable|null) given.
PHP 7.1 – 7.3 (4 errors)
========== Full reportPHP 7.4 – 8.0 (3 errors)
PHP 7.1 – 7.3 (4 errors)
|
Bug report
Types applied to callable doesn't seems to be correctly inferred.
Code snippet that reproduces the problem
https://phpstan.org/r/24105e02-8d5f-4fd9-a237-01ebec9938a9
Expected output
Both lines 29 and 34 should raise
Else branch is unreachable because ternary operator condition is always true.
, only line 29 does.Line 34 error reveals that the callable is inferred to
callable(mixed): DateTimeImmutable
generic should have been propagated to the callable and it should expectcallable(T of DateTime): DateTimeImmutable
The text was updated successfully, but these errors were encountered: