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
Add template support to callable property phpdoc #8964
Comments
What you're asking for is generic callables/closures:
This is very easy to achieve since both CallableType and ClosureType can contain TemplateTypeMap. We need support for this syntax in phpstan/phpdoc-parser. |
@mvorisek After the latest push in 1.10.x, PHPStan now reports different result with your code snippet: @@ @@
13: PHPDoc tag @var for property Cl::$prop contains unresolvable type.
-13: Property Cl::$prop has no type specified.
+13: Property Cl::$prop has no type specified.
+19: Tip: Method Cl::method() always throws an exception, it should have return type "never". Full report
|
Fixed a mistake in your example: https://phpstan.org/r/fb6ebb4f-3db2-4c46-99b3-be10a1afacf5 |
@dktapps yes, thank you, I have updated the description. (if anyone read this, there was a typo |
Hi @ondrejmirtes, implemented in phpstan/phpdoc-parser#199, can I please ask you to review it? |
however assign to a property is still not working - https://phpstan.org/r/7e370b44-57fa-4bcf-9a1d-24a0bbf3834e /cc @mad-briller |
Closures do not support PHPDocs above them, you can't mark your closure as generic. There's an open feature request about PHPDocs above closures. |
You probably opened the (old) repro from this issue description, in the last post, I have linked sensual repro. To avoid confusion, I have linked it in the issue description as well. |
The question is - why it works for methods and not for property assignments. I'm not really sure. Another question is - how these should be validated in regard to generics and TemplateTypeMap, I'm also not sure. |
Here is a little better repro - https://phpstan.org/r/bb9171d8-60f4-477c-9b2a-3e8d867d3a74
passes but
emits phpstan error. It seems the callable template of the property is resolved before the assign. |
Feature request
https://phpstan.org/r/fb6ebb4f-3db2-4c46-99b3-be10a1afacf5https://phpstan.org/r/7e370b44-57fa-4bcf-9a1d-24a0bbf3834e
Closure
type in property should be possible to describe the same way as in method phpdoc.The text was updated successfully, but these errors were encountered: