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

Emit redundant/impossible condition when the result of a pure getter is compared to itself #6153

Open
weirdan opened this issue Jul 21, 2021 · 1 comment

Comments

@weirdan
Copy link
Collaborator

weirdan commented Jul 21, 2021

https://psalm.dev/r/2b1b91e0d1

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/2b1b91e0d1
<?php
/** @psalm-immutable */
final class Mass {
    public function __construct(private int $value) {}
    public function getValue(): int { return $this->value; }
}

$masses = [new Mass(1), new Mass(2)];

foreach ($masses as $mass) {
    if ($mass->getValue() === $mass->getValue()) {} // should be flagged as RedundantCondition
    if ($mass->getValue() !== $mass->getValue()) {} // should be flagged as impossible
}
Psalm output (using commit a2c87b8):

No issues!

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

1 participant