Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inherit value-of class constant (static behavior) #10899

Open
distantnative opened this issue Apr 11, 2024 · 1 comment
Open

Inherit value-of class constant (static behavior) #10899

distantnative opened this issue Apr 11, 2024 · 1 comment

Comments

@distantnative
Copy link

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?

Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant