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

Psalm misidentifies type with type juggling #6965

Open
kamil-tekiela opened this issue Nov 22, 2021 · 2 comments
Open

Psalm misidentifies type with type juggling #6965

kamil-tekiela opened this issue Nov 22, 2021 · 2 comments

Comments

@kamil-tekiela
Copy link
Contributor

https://psalm.dev/r/c831c824de

According to type juggling rules false == 0 so the condition ensures that $var is not false. Yet, Psalm complains that the variable might be false.

@psalm-github-bot
Copy link

I found these snippets:

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

/** @return int|false */
function a()
{
	return rand(0,1) ? false : 1;
}

$var = a();
if($var != 0){
	$var += 1;
}
Psalm output (using commit 9943efb):

ERROR: PossiblyFalseOperand - 11:2 - Left operand cannot be falsable, got false|int

INFO: UnusedVariable - 11:2 - $var is never referenced or the value is not used

@orklah
Copy link
Collaborator

orklah commented Nov 22, 2021

Psalm has limited support of assertions with ==. This could probably be improved, even if the rules in PHP are a pain.

Also related: #1712

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

2 participants