You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class GenericObjectFactory
{
/**
* @psalm-template T
* @psalm-param class-string<T> $type
* @psalm-return T
*/
public function getObject(string $type)
{
return 3;
}
}
<?php
class GenericObjectFactory
{
/**
* @psalm-template T of object
* @psalm-param class-string<T> $type
* @psalm-return T
*/
public function getObject(string $type)
{
return 3;
}
}
This is motivated by a docblock I added to jms/serializer, and the hope that implementing this feature would catch possible errors in implementations of that interface.
The text was updated successfully, but these errors were encountered:
bdsl
changed the title
Implementation of generic object factory should be constrained to return an object
Generic object factory should be constrained to return an object
Jun 4, 2019
Psalm currently reports no issues with the following code:
But since we have a class-string<T>, I think psalm could know that T must be an object type, and so interpret the code as equivalent to the following, for which it does report InvalidReturnStatement and InvalidReturnType:
This is motivated by a docblock I added to jms/serializer, and the hope that implementing this feature would catch possible errors in implementations of that interface.
The text was updated successfully, but these errors were encountered: