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

Invalid type detect after AND condition #11083

Open
vjik opened this issue Aug 24, 2024 · 1 comment
Open

Invalid type detect after AND condition #11083

vjik opened this issue Aug 24, 2024 · 1 comment

Comments

@vjik
Copy link
Contributor

vjik commented Aug 24, 2024

https://psalm.dev/r/d946add113

In this case RedundantCondition is invalid.

Copy link

I found these snippets:

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

class Obj {
    public function __construct(
    	private int $value,
    ) {}    
    public function isEqual(Obj $b): bool
    {
        return $this->value === $b->value;
    }
}

function isEqual(?Obj $a, ?Obj $b): bool
{
    if ($a === null && $b === null) {
        return true;
    }
    
    /** @psalm-trace $a, $b */
    
    if (
        ($a === null && $b !== null)
        || ($a !== null && $b === null)
    ) {
        return false;
    }

    return $a->isEqual($b);
}
Psalm output (using commit 16b24bd):

ERROR: RedundantCondition - 22:25 - Obj can never contain null

ERROR: RedundantCondition - 23:13 - Obj can never contain null

INFO: Trace - 21:5 - $a: Obj

INFO: Trace - 21:5 - $b: Obj

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