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

Backed enums should not behave as if they were values of their backing type #10082

Closed
Guuzen opened this issue Aug 3, 2023 · 8 comments · Fixed by #10150
Closed

Backed enums should not behave as if they were values of their backing type #10082

Guuzen opened this issue Aug 3, 2023 · 8 comments · Fixed by #10150
Labels

Comments

@Guuzen
Copy link
Contributor

Guuzen commented Aug 3, 2023

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

@Guuzen Guuzen changed the title Psalm allows to create enum from enum item Psalm allows to create enum from an enum item Aug 3, 2023
@weirdan
Copy link
Collaborator

weirdan commented Aug 3, 2023

It seems the snippet link is wrong.

@Guuzen
Copy link
Contributor Author

Guuzen commented Aug 3, 2023

sorry, updated the link

@weirdan
Copy link
Collaborator

weirdan commented Aug 3, 2023

@psalm-github-bot
Copy link

I found these snippets:

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

enum Foo: string
{
    case A = 'a';
    case B = 'b';
}


Foo::from(Foo::A);
Psalm output (using commit 73ebe22):

No issues!

@vimeo vimeo deleted a comment from psalm-github-bot bot Aug 3, 2023
@weirdan
Copy link
Collaborator

weirdan commented Aug 3, 2023

It's actually worse than that: https://psalm.dev/r/7b54faf536

@psalm-github-bot
Copy link

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);
Psalm output (using commit 73ebe22):

No issues!

@weirdan weirdan added the bug label Aug 3, 2023
@weirdan 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 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
@weirdan
Copy link
Collaborator

weirdan commented Aug 14, 2023

@boesing
Copy link
Contributor

boesing commented Aug 14, 2023

@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
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants