psalm icon indicating copy to clipboard operation
psalm copied to clipboard

@psalm-require-extends does not consider generics

Open alex-dev opened this issue 10 months ago • 1 comments

https://psalm.dev/r/346857a814

alex-dev avatar Apr 11 '24 14:04 alex-dev

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

psalm-github-bot[bot] avatar Apr 11 '24 14:04 psalm-github-bot[bot]