Skip to content

Fix not always positive bit operations#5233

Merged
muglug merged 3 commits intovimeo:masterfrom
orklah:bits-operations-are-weird
Feb 16, 2021
Merged

Fix not always positive bit operations#5233
muglug merged 3 commits intovimeo:masterfrom
orklah:bits-operations-are-weird

Conversation

@orklah
Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown
Contributor

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

@orklah
Copy link
Copy Markdown
Collaborator Author

orklah commented Feb 15, 2021

Thanks! Added!

@muglug muglug merged commit 7b24552 into vimeo:master Feb 16, 2021
@muglug
Copy link
Copy Markdown
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