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

Strange DocblockTypeContradiction on value-of<enum> @property condition #11019

Open
flaviovs opened this issue Jun 20, 2024 · 1 comment
Open

Comments

@flaviovs
Copy link

https://psalm.dev/r/506dc7f7d9

As you can see on line 32, the warning goes away if we invert the testing order.

Copy link

I found these snippets:

https://psalm.dev/r/506dc7f7d9
<?php

enum Foo: string
{
	case Bar = 'bar';
    case Lee = 'lee';
}

/** @property value-of<Foo> $attr */
class A
{
    public function __set(string $name, mixed $value) {}
    public function __get(string $name): mixed { return null; }

    public function expensiveCalculation(): bool
    {
        return rand(0, 10) > 5;
    }

    public function thisWorks(): bool
    {
        return $this->attr === Foo::Bar->value;
    }

    public function thisFails(): bool
    {
        return $this->attr === Foo::Bar->value && $this->expensiveCalculation();
    }

    public function butThisWorks(): bool
    {
        return $this->expensiveCalculation() && $this->attr === Foo::Bar->value;
    }
}
Psalm output (using commit 16b24bd):

ERROR: DocblockTypeContradiction - 27:16 - Docblock-defined type value-of<Foo> for $this->attr is never =string(bar)

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

1 participant