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

UndefinedConstant when using enum property as const array key #9373

Closed
Brajk19 opened this issue Feb 22, 2023 · 3 comments
Closed

UndefinedConstant when using enum property as const array key #9373

Brajk19 opened this issue Feb 22, 2023 · 3 comments

Comments

@Brajk19
Copy link

Brajk19 commented Feb 22, 2023

When using Enum::CASE->value or Enum::CASE->name as key in constant, psalm throws UndefinedConstant error.
No error is thrown when enum property is used as key in regular array (not const).

https://psalm.dev/r/3307971eb7

@psalm-github-bot
Copy link

psalm-github-bot bot commented Feb 22, 2023

I found these snippets:

https://psalm.dev/r/3307971eb7
<?php

enum MyEnum: int
{
    case CASE_1 = 3;
    case CASE_2 = 4;
}

class A {
    public const MY_CONST = [
        MyEnum::CASE_1->value => 'enum case 1',
        MyEnum::CASE_2->value => 'enum case 1',
    ];
}

class B {
    public const MY_CONST = [
        3 => 'enum case 1',
        4 => 'enum case 1',
    ];
}


echo A::MY_CONST[MyEnum::CASE_1->value];
echo B::MY_CONST[MyEnum::CASE_1->value];
Psalm output (using commit c8f7b7e):

ERROR: UndefinedConstant - 24:6 - Constant A::MY_CONST is not defined

INFO: MixedArrayAccess - 24:6 - Cannot access array value on mixed variable A::MY_CONST

INFO: MixedArgument - 24:6 - Argument 1 of echo cannot be mixed, expecting string

ygottschalk added a commit to ygottschalk/psalm that referenced this issue Feb 23, 2023
@weirdan
Copy link
Collaborator

weirdan commented Feb 24, 2023

The linked commit looks like it should fix it.

ygottschalk added a commit to ygottschalk/psalm that referenced this issue Feb 24, 2023
@ygottschalk
Copy link
Contributor

Still working on it, did not really fix the issue. PR should be incoming today

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

No branches or pull requests

3 participants