psalm icon indicating copy to clipboard operation
psalm copied to clipboard

Inherit `value-of` class constant (static behavior)

Open distantnative opened this issue 10 months ago • 1 comments

How could I realize the follow (if at all)?

https://psalm.dev/r/e2f5c88bc0

Where in class B the template T would be of BItem as declared by the ITEM_CLASS const?

distantnative avatar Apr 11 '24 11:04 distantnative

I found these snippets:

https://psalm.dev/r/e2f5c88bc0
<?php

class Item {}
class BItem extends Item {}

/**
 * @template T
 */
class Base {
	
}

/**
 * @extends Base<value-of<self::ITEM_CLASS>>
 */
class A extends Base {
	public const ITEM_CLASS = Item::class;
}

/**
 * @extends A
 */
class B extends A {
    public const ITEM_CLASS = BItem::class;
}
Psalm output (using commit ef3b018):

ERROR: InvalidDocblock - 23:1 - @template-extends has invalid class A

INFO: InvalidClassConstantType - 24:18 - The type "BItem::class" for B::ITEM_CLASS does not satisfy the type "Item::class" inherited from A::ITEM_CLASS

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