Skip to content

Generic return type via static method damage template type (with bound) #3251

@hrach

Description

@hrach

Bug report

https://phpstan.org/r/f04e6af3-c413-4d94-93b4-0b9b21572598

class E {}

/**
 * @template T of E
 */
class R {
	/** @var T */
	public $e;
	
	/** @return T */
	function ret() { return $this->e; } // nonsense, to silence missing return
	
	function test(): void {
		$this->e = static::ret(); // not ok
		$this->e = self::ret(); // not ok
		$this->e = $this->ret(); // ok
	}
}

self::ret() is evaluated to E type

Property R<T of E>::$e (T of E) does not accept E.

Expected output

No error

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions