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
Generic return type via static method damage template type (with bound) #3251
Comments
You're losing the instance-level |
It's not really called statically, though: <?php declare(strict_types = 1);
class E {}
class EChild extends E {};
/**
* @template T of E
*/
class R {
/** @var T */
private $t;
/** @param T $t */
public function __construct($t) {
$this->t = $t;
}
/** @return T */
public function ret() {
var_dump(get_class($this->t));
return $this->t;
}
public function test(): void {
$this->t = static::ret();
$this->t = self::ret();
$this->t = $this->ret();
}
}
(new R(new EChild()))->test(); results in
|
Yeah, I get it, we should figure out which |
Well, actually, I wanted to have this behavior on real static. I think the bug is it doesn't report unknown T definition over the static method. |
Next reproduction of the same bug: https://phpstan.org/r/8ca83eff-7db3-4e98-a322-1d963e20aabb |
@hrach After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-16: Property R<T of E>::$e (T of E) does not accept E.
-17: Property R<T of E>::$e (T of E) does not accept E.
+16: Property R<T of E>::$e (T of E) does not accept E. Full report
|
@hrach After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
13: Method R::ret() should return class-string<T of E> but returns string.
-16: Property R<T of E>::$e (class-string<T of E>) does not accept class-string<E>.
-17: Property R<T of E>::$e (class-string<T of E>) does not accept class-string<E>.
+16: Property R<T of E>::$e (class-string<T of E>) does not accept class-string<E>. Full report
|
@LukasVitek After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-44: Method Parameters::add() should return Parameters<TCriterion of IOrderCriterion> but returns Parameters<IOrderCriterion>.
+No errors |
@hrach After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-16: Property R<T of E>::$e (T of E) does not accept E.
-17: Property R<T of E>::$e (T of E) does not accept E.
+No errors |
@hrach After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-13: Method R::ret() should return class-string<T of E> but returns string.
-16: Property R<T of E>::$e (class-string<T of E>) does not accept class-string<E>.
-17: Property R<T of E>::$e (class-string<T of E>) does not accept class-string<E>.
+13: Method R::ret() should return class-string<T of E> but returns string. Full report
|
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug report
https://phpstan.org/r/f04e6af3-c413-4d94-93b4-0b9b21572598
self::ret()
is evaluated toE
typeExpected output
No error
The text was updated successfully, but these errors were encountered: