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
I tried to build a generic interface that has a parse method that returns an instance of T. However, the implementation seems to expect to have T in the place of the return type. This is not possible because it doesn't exist at run time and will throw an error.
a.php PhanTypeMismatchReturn Returning false of type false but parse(string $value) is declared to return ?T
a.php PhanTypeMismatchReturn Returning 0 of type 0 but parse(string $value) is declared to return ?T
...did not work, so I suspected that phan has issues with the nullability here. That doesn't seem to be the case either:
a.php PhanTypeMismatchReturn Returning false of type false but parse(string $value) is declared to return T
a.php PhanTypeMismatchReturn Returning 0 of type 0 but parse(string $value) is declared to return T
Next, I've read in the documentation that generic interfaces don't seem to be supported, so I tried using an abstract class. It seems to yield the same result:
a.php:17 PhanParamSignatureMismatch Declaration of function doWork() : T should be compatible with function doWork() : T defined in a.php:12
a.php:17 PhanTypeMismatchReturn Returning false of type false but doWork() is declared to return T
It seems that SomeClass1 works without any issues here, the error only applies to ?bool. When adding an additional /** @return ?bool */, it seems to work. My guess is that phan sometimes ignores the types that are written in actual PHP code, not in the PHPDoc.
Is this the intended behavior? How to I type this correctly?
$ ./vendor/bin/phan --version
Phan 5.4.3
php-ast version 1.1.1
PHP version used to run Phan: 8.3.3-1+ubuntu22.04.1+deb.sury.org+1
The text was updated successfully, but these errors were encountered:
I tried to build a generic interface that has a parse method that returns an instance of
T
. However, the implementation seems to expect to haveT
in the place of the return type. This is not possible because it doesn't exist at run time and will throw an error.Examples:
...did not work, so I suspected that phan has issues with the nullability here. That doesn't seem to be the case either:
Next, I've read in the documentation that generic interfaces don't seem to be supported, so I tried using an abstract class. It seems to yield the same result:
It seems that
SomeClass1
works without any issues here, the error only applies to?bool
. When adding an additional/** @return ?bool */
, it seems to work. My guess is that phan sometimes ignores the types that are written in actual PHP code, not in the PHPDoc.Is this the intended behavior? How to I type this correctly?
The text was updated successfully, but these errors were encountered: