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

InvalidArgument vs PossiblyFalseArgument #5790

Closed
gdejong opened this issue May 18, 2021 · 3 comments · Fixed by #6083
Closed

InvalidArgument vs PossiblyFalseArgument #5790

gdejong opened this issue May 18, 2021 · 3 comments · Fixed by #6083

Comments

@gdejong
Copy link
Contributor

gdejong commented May 18, 2021

A method expecting a string, but passed true outputs an InvalidArgument:

https://psalm.dev/r/47caf98787

Same thing, but now passed false outputs a PossiblyFalseArgument:

https://psalm.dev/r/0b9b837d1d

In this case false is not "possibly" false, it definitely is false.

Is this intentional behavior or a bug?

(I would have expected an InvalidArgument error in the second case as well)

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/47caf98787
<?php
declare(strict_types=1);

function takesAString(string $s): void{
  echo $s;   
}

takesAString(true);
Psalm output (using commit d82f028):

ERROR: InvalidArgument - 8:14 - Argument 1 of takesAString expects string, true provided
https://psalm.dev/r/0b9b837d1d
<?php
declare(strict_types=1);

function takesAString(string $s): void{
  echo $s;   
}

takesAString(false);
Psalm output (using commit d82f028):

ERROR: PossiblyFalseArgument - 8:14 - Argument 1 of takesAString cannot be false, possibly false value provided

@weirdan
Copy link
Collaborator

weirdan commented May 18, 2021

It is intentional, although it could be clearer. The reason is that many internal functions return false in error scenarios, although it's often desired to ignore that. So having a separate issue lets you ignore specifically that. There's also PossiblyNullArgument, for the same reason.

@orklah
Copy link
Collaborator

orklah commented May 18, 2021

Shouldn't the false case be handled by the @ignore-falsable-return flag instead and be declared as a real InvalidArgument when it's not? In this case, a literal should definitely reported as the biggest error level possible

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.

3 participants