Skip to content

Generics does not respect type but fallback to basic types #6699

@bastien-phi

Description

@bastien-phi

Bug report

Not sure if it was already reported but it looks like generics fallback to basic type and does not keep defined type.

Code snippet that reproduces the problem

/**
 * @template TValue
 */
class Foo
{
	/** @var TValue */
	public $value;
	
	/**
	 * @param TValue $value
	 */
	public function __construct($value) {
	  $this->value = $value;	
	}
}

/** @var class-string<Exception> $exceptionClass */
dumpType((new Foo($exceptionClass))->value);

https://phpstan.org/r/94faaba1-0ed2-4d54-8ff0-130a0bf2fb03

Expected output

We expect the value to be of type class-string<Exception>.

Did PHPStan help you today? Did it make you happy in any way?

As always, amazing tool. It makes me more confident on my code. Great job !

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions