-
Notifications
You must be signed in to change notification settings - Fork 668
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
Bug: missing InvalidArgument error when passing false to true param #9267
Comments
I found these snippets: https://psalm.dev/r/2c91682853<?php
/**
* @param true|string $arg
* @return void
*/
function foo( $arg = true ) {
if ( $arg === true ) {
echo "Yes";
}
}
foo( false );
foo( 123 );
|
Interesting, this is caused by this line: psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php Line 864 in 1c19260
the param "ignore_false" is set to true by default on this check. It's a little surprising because we have other mechanisms to ignore false for internal functions so I don't get why it's put to true here. Maybe try to push a PR putting that to false and let's see where the CI goes? |
See the PR created, it fails in tons of places then. shepherd runs with https://psalm.dev/docs/running_psalm/configuration/#ignoreinternalfunctionfalsereturn true or false? |
Yeah, that's the other mechanism I was talking about earlier. Could you try to change this line:
into if ($input_type_part instanceof TFalse && ($ignore_false || $input_type->ignore_falsable_issues)) {
When shepherd runs, it is supposed to ignore falsable from internal functions |
Done, looks better but it seems there are some underlying logic issues with InvalidArgument, InvalidScalarArgument and PossiblyFalseArgument, since they have some overlap. I also tried removing the first commit with the suggestion of #9267 (comment), however then those that fail for some weird reason also fail, so there seems to be some issue there. Feel free to check/debug/fix this further, as I currently don't have time to contribute. |
Yep, that was not the correct fix. Can you try
instead of
on the call here: psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php Line 864 in 1c19260
(and reverting the rest) Apparently, it's done like that on other calls. It seems to fix your case and another test that failed on the previous fixes, let's see if the rest of CI pass |
Changed now, but there are tons of tests that fail (however for some it looks like they should fail and the tests are buggy) |
Yeah, looks much better IMHO. I think there's some cases where echo doesn't accept null that would need to get changed to reduce obstacles, but the rest seems legit at first glance |
Oh, there's something wrong though: https://github.com/vimeo/psalm/actions/runs/4155594465/jobs/7188799901#step:5:41 Somehow, it seems it's the same issue that makes null be reported with echo. This was handled here before: psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php Line 1077 in 1c19260
|
Sorry, I cannot check that any further until some time next month |
No worries, seems like this bug is very old, it can wait! |
https://psalm.dev/r/2c91682853
When passing
false
to the param, it should report asInvalidArgument
just like it does for when we pass123
The text was updated successfully, but these errors were encountered: