-
-
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
function (Model $x) {}
passed to Closure(object): void
is not reported in level <=6
#7342
Comments
Closure(Cl)
should accept Closure(X extends Cl)
as Closure(object)
does on level 3
@mvorisek After the latest push in 1.11.x, PHPStan now reports different result with your code snippet: @@ @@
-25: Property UserAction::$enabled2 (bool|(Closure(Model): bool)) does not accept Closure(X): false.
+No errors |
Changed: phpstan/phpstan-src@eceb9f6 |
Decided to revert the fix. |
Allowing Example:
Maybe this should be solved with something like type projection like in phpstan/phpdoc-parser#138 as " So the clean way to allow Closure with subclass params acceptance should be like @jiripudil what do you think real world example: https://github.com/atk4/ui/blob/67cfdbd00d/src/Form/Control/Lookup.php#L57 the property must accept |
This is correctly reported https://phpstan.org/r/94ae1e00-8bb6-47dd-aa9e-06fad4a45880 |
That is correct. But currently, phpdoc cannot be used to specify the Closure should accept class that is or extends Model as the 1st param. This issue is to allow such requirement properly documented better than |
Type projections wouldn't help you, even if we implemented them for Closures; you'd need a covariant projection, but Closure/callable parameters are contravariant, as you've demonstrated. That's an impossible combination. |
You are both right. With #8964 implemented... I have updated the issue title and the description. |
Closure(Cl)
should accept Closure(X extends Cl)
as Closure(object)
does on level 3function (Model $x) {}
passed to Closure(object): void
is not reported in level <=6
Bug report
Currently, with level 3 - 6,Closure(object)
acceptsClosure(X extends Cl)
, butClosure(Cl)
does not. This is inconsistent asobject
is a weaker type.With #8964 implemented, this issue should actually aim to not accept
function (Model $x) {}
intoClosure(object): void
property/param.Code snippet that reproduces the problem
repro: https://3v4l.org/gIfXB (TypeErrorException)
https://phpstan.org/r/9e11c8b2-622b-4520-88c1-10ec04c86378 (no phpstan error for level <= 6)
Expected output
phpstan type error
The text was updated successfully, but these errors were encountered: