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

Can not use class constants type as part of new list{} (n-tuple) types #8844

Closed
gmazzap opened this issue Dec 5, 2022 · 2 comments
Closed

Comments

@gmazzap
Copy link

gmazzap commented Dec 5, 2022

In Psalm v5, we can now define n-tuple types via list{T1, T2}.

For a while now, we can also use ClassName::SOME_PREFIX_* to declare a type pointing to a set of class constants having a given prefix.

However, we can't use the two things together. See:

https://psalm.dev/r/f185d94aae

I'm guessing Psalm finds a :: inside an array-type definition and assumes it is an array key, not considering it could be an array value.

Edit: please note, in array-shapes definition it works: https://psalm.dev/r/9df7ce7dca so looks like it is really a matter of Psalm assuming :: is used in the key.

@psalm-github-bot
Copy link

I found these snippets:

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

class Test
{
    public const C_1 = 'one';
    public const C_2 = 'two';
    
    /**
     * @return list{Test::C_*, bool}
     */
    public function pickOne(): array
    {
        $value = random_int(0, 5) > 2 ? self::C_1 : self::C_2;
        
        return [$value, true];
    }
}
Psalm output (using commit 1cd10c3):

ERROR: InvalidDocblock - 11:5 - :: in array key is only allowed for ::class in docblock for Test::pickOne

@weirdan
Copy link
Collaborator

weirdan commented Feb 9, 2024

Implemented in #10678

@weirdan weirdan closed this as completed Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants