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

PossiblyFalseOperand: false is not erased after > 0 comparison #8745

Closed
derrabus opened this issue Nov 23, 2022 · 4 comments · Fixed by #8753
Closed

PossiblyFalseOperand: false is not erased after > 0 comparison #8745

derrabus opened this issue Nov 23, 2022 · 4 comments · Fixed by #8753

Comments

@derrabus
Copy link

Found while testing 5.0.0-rc1

https://psalm.dev/r/72fd1e5782

A variable typed as int|false is compared with zero ($length > 0). Afterwards, Psalm correctly infers that it has to be 1 or higher (int<1, max>). But it still considers false to be possible although (false > 0) === false.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/72fd1e5782
<?php

function formatVarchar(int|false $length): string
{
    return $length > 0 ? 'VARCHAR(' . $length . ')' : 'VARCHAR';
}
Psalm output (using commit 8f39de9):

ERROR: PossiblyFalseOperand - 5:39 - Cannot concatenate with a possibly false false|int<1, max>

@orklah
Copy link
Collaborator

orklah commented Nov 23, 2022

Thanks for reporting!

Given that you tested the beta, this would be a new regression in the RC, correct?

@derrabus
Copy link
Author

This happened on a different codebase than I tested the beta on. I can't tell whether the beta was affected already, sorry.

orklah added a commit to orklah/psalm that referenced this issue Nov 24, 2022
@orklah orklah mentioned this issue Nov 24, 2022
orklah added a commit that referenced this issue Nov 24, 2022
@derrabus
Copy link
Author

Thank you for the quick bugfix! 🚀

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

Successfully merging a pull request may close this issue.

2 participants