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
Suddenly duplicate RedundantCondition for constants #7241
Comments
I found these snippets: https://psalm.dev/r/3c04ed05dc<?php
define( 'HELLO', false );
if ( defined( 'HELLO' ) && HELLO ) {
echo "world";
}
|
This is more or less expected. I'll explain. The issue was revealed by #7054. In this PR, I allowed global constants to have variable identifiers. Which means, they can now be the target of assertions Assertions is the module Psalm use to refine the type of a variable depending on the checks that are made on it in a specific context. For example, in https://psalm.dev/r/e4129d69f0, the first value of HELLO is Before my #7054, both branches of the conditional for this snippet showed The assertion module emits an issue whenever it sees an impossible or redundant check on a variable and it works on the whole condition (that's why it reports an error pretty wide with On the other hand, we have an other check that just report any operand that is always truthy or always falsy, no matter what the source of the type is. For example, functions calls or literals: https://psalm.dev/r/d4a047a858 Your snippet match boths modules. It's a constant that happens to be always false so it triggers 2 errors. I'm not perfectly sure how to fix this to prevent overlaps while still covering every cases. I have two ideas:
It's pretty low priority for me though as both error can be suppressed in a single annotation and it's not a big bother from my point of view |
I found these snippets: https://psalm.dev/r/e4129d69f0<?php
define( 'HELLO', false );
if (HELLO) {
/** @psalm-trace $a */
$a = HELLO;
}
else {
/** @psalm-trace $b */
$b = HELLO;
}
https://psalm.dev/r/d4a047a858<?php
if(0){
}
if(returnzero()){
}
/** @return 0 */
function returnzero(){
return 0;
}
|
Thanks for clarifying this is "on purpose". Since the errors are correct, I will just mark it as closed as it's documented now why this behavior exists. |
#7054 has been reverted |
https://psalm.dev/r/3c04ed05dc
Until recently it only reported 1 error:
ERROR: TypeDoesNotContainType - 5:28 - Operand of type false is always false
Since 4.16 (I think) it suddenly reports 2 errors for the same thing, as it now added:
ERROR: TypeDoesNotContainType - 5:6 - Type false for HELLO is always falsy
The text was updated successfully, but these errors were encountered: