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

Fix not always positive bit operations #5233

Merged
merged 3 commits into from Feb 16, 2021

Conversation

orklah
Copy link
Collaborator

@orklah orklah commented Feb 15, 2021

This should fix #5227

I'll wait to see failing tests to see if I just fix them or if I add this example: https://psalm.dev/r/2ba369ca91

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/2ba369ca91
<?php

$a = 1;
$b = 1;
$c = 32;
$d = 64;

if (0 === ($a ^ $b)) {
    echo "Actually, zero\n";
}

if (0 === ($a >> $b)) {
    echo "Actually, zero\n";
}

if (8 === PHP_INT_SIZE) {
    if (0 === ($a << $d)) {
        echo "Actually, zero\n";
    }
} else {
    if (0 === ($a << $c)) {
        echo "Actually, zero\n";
    }
}
Psalm output (using commit 77feecb):

ERROR: TypeDoesNotContainType - 8:5 - positive-int cannot be identical to 0

ERROR: TypeDoesNotContainType - 12:5 - positive-int cannot be identical to 0

ERROR: TypeDoesNotContainType - 17:9 - positive-int cannot be identical to 0

ERROR: TypeDoesNotContainType - 21:9 - positive-int cannot be identical to 0

@sad-spirit
Copy link
Contributor

I think you missed \PhpParser\Node\Expr\BinaryOp\BitwiseAnd from the original report.

@orklah
Copy link
Collaborator Author

orklah commented Feb 15, 2021

Thanks! Added!

@muglug muglug merged commit 7b24552 into vimeo:master Feb 16, 2021
@muglug
Copy link
Collaborator

muglug commented Feb 16, 2021

Thanks!

This was referenced Mar 11, 2021
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 this pull request may close these issues.

"RedundantCondition - positive-int can never contain 0" on a result of a bit & operation that can be 0
3 participants