-
Notifications
You must be signed in to change notification settings - Fork 660
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
Backed enums should not behave as if they were values of their backing type #10082
Labels
Comments
Guuzen
changed the title
Psalm allows to create enum from enum item
Psalm allows to create enum from an enum item
Aug 3, 2023
It seems the snippet link is wrong. |
sorry, updated the link |
I found these snippets: https://psalm.dev/r/a843ec35f3<?php
enum Foo: string
{
case A = 'a';
case B = 'b';
}
Foo::from(Foo::A);
|
It's actually worse than that: https://psalm.dev/r/7b54faf536 |
I found these snippets: https://psalm.dev/r/7b54faf536<?php
enum Foo: string
{
case A = 'a';
}
enum Bar: int {
case A = 1;
}
function f(string|array $_p): void {}
f(Foo::A);
function f2(int $_p): void {}
f2(Bar::A);
|
weirdan
changed the title
Psalm allows to create enum from an enum item
Enums should not behave as if they were values of their backing type
Aug 3, 2023
weirdan
changed the title
Enums should not behave as if they were values of their backing type
Backed enums should not behave as if they were values of their backing type
Aug 3, 2023
It looks like it was added intentionally. @boesing can you clarify? |
@weirdan there should be a test in the PR. most probably thats an unwanted side-effect. 🫤 PR was introducing value-of functionality. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://psalm.dev/r/a843ec35f3
But in reality it is not possible and we will get a runtime error in this case.
https://3v4l.org/ovHD0
The text was updated successfully, but these errors were encountered: