psalm
psalm copied to clipboard
@psalm-require-extends does not consider generics
https://psalm.dev/r/346857a814
I found these snippets:
https://psalm.dev/r/346857a814
<?php
/** @template T */
class A {
/** @param T $a */
public function __construct(protected readonly $a) {}
}
/**
* @template T
* @psalm-require-extends A<T>
*/
trait C {
/** @return T */
public function a() { return $this->a; }
}
/**
* @template T
* @extends A<T>
*/
class B extends A {
/** @use C<T> */
use C;
}
/** @psalm-trace $_a */
$_a = (new B('ssss'))->a();
Psalm output (using commit ef3b018):
INFO: Trace - 28:1 - $_a: mixed
ERROR: ExtensionRequirementViolation - 24:6 - C requires using class to extend A<T>, but B does not