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

Add way to annotate BackedEnum backing type #8268

Open
AndrolGenhald opened this issue Jul 15, 2022 · 3 comments · May be fixed by #10907
Open

Add way to annotate BackedEnum backing type #8268

AndrolGenhald opened this issue Jul 15, 2022 · 3 comments · May be fixed by #10907

Comments

@AndrolGenhald
Copy link
Collaborator

AndrolGenhald commented Jul 15, 2022

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.

  • Add template to BackedEnum interface
  • Add annotation to specify backing type when declaring enum (@enum<int> maybe?)
  • Check annotation against PHP backing type (can only be string or int, but you can't use @enum<positive-int> with enum Foo: string)
  • Check annotation against cases (case Bar = 0 should show an issue for @enum<positive-int>)
  • The BackedEnum template needs to be filled in from the @enum<[type]> annotation so that BackedEnum::from, ::tryFrom, and ::cases use the correct type
@weirdan
Copy link
Collaborator

weirdan commented Nov 24, 2022

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

@AndrolGenhald
Copy link
Collaborator Author

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
Copy link
Collaborator

weirdan commented Nov 24, 2022

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

@michaelcozzolino michaelcozzolino linked a pull request Apr 14, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants