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

Internal: non-strict checking leads to inconsistent behavior #10501

Closed
kkmuffme opened this issue Dec 18, 2023 · 2 comments · Fixed by #10502
Closed

Internal: non-strict checking leads to inconsistent behavior #10501

kkmuffme opened this issue Dec 18, 2023 · 2 comments · Fixed by #10502

Comments

@kkmuffme
Copy link
Contributor

https://psalm.dev/r/30076adf91

There are phpcs rules that disallow this already, however it might be too intrusive, bc it will disallow this in all cases, instead of only when necessary (e.g. Squiz.Operators.ComparisonOperatorUsage.ImplicitFalse and Squiz.Operators.ComparisonOperatorUsage.ImplicitTrue or Squiz.Operators.ComparisonOperatorUsage)

There should be a psalm check for these, where a union of falsy types is flagged.

This is an internal issue (e.g. #10500 was only necessary bc of the non-strict checking) but I probably also affects psalm users's codebases.

Copy link

I found these snippets:

https://psalm.dev/r/30076adf91
<?php

/**
 * @param array|null $arg
 * @return void
 */
function foo($arg) {
	if ($arg) {
    	// this is risky, bc the empty array and null case are handled together
    }
    
    if (!$arg) {
     	// this is risky, bc the empty array and null case are handled together  
    }
}
Psalm output (using commit a75d26a):

No issues!

@kkmuffme
Copy link
Contributor Author

Will create a PR for this

kkmuffme added a commit to kkmuffme/psalm that referenced this issue Dec 18, 2023
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Jan 12, 2024
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Jan 12, 2024
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Jan 13, 2024
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Jan 13, 2024
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Jan 13, 2024
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Jan 15, 2024
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.

1 participant