vimeo / psalm

A static analysis tool for finding errors in PHP applications
https://psalm.dev
MIT License
5.56k stars 660 forks source link

Add way to annotate BackedEnum backing type #8268

Open AndrolGenhald opened 2 years ago

AndrolGenhald commented 2 years ago

I want to be able to take a BackedEnum<string> $enum so that $enum->value is definitely a string. Currently I have false positives because BackedEnum::$value is int|string.

weirdan commented 1 year ago

@implements BackedEnum<Type> is probably easier to implement.

AndrolGenhald commented 1 year ago

I would think @extends probably? Aren't backed enums implemented as classes extending BackedEnum with a bunch of additional constraints? Looking at this again though you're right that a new annotation for that shouldn't be necessary.

weirdan commented 1 year ago

Both BackedEnum and UnitEnum are interfaces, so it would be @implements