1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Always emit InvalidArgument when the parameter is always false and not accepted

This commit is contained in:
orklah 2021-07-13 00:06:36 +02:00
parent e93b37a225
commit 688367de38
2 changed files with 37 additions and 15 deletions

View File

@ -1115,12 +1115,24 @@ class ArgumentAnalyzer
}
}
if ($input_type->isFalsable()
&& !$param_type->hasBool()
&& !$param_type->hasScalar()
&& !$input_type->ignore_falsable_issues
&& $cased_method_id !== 'echo'
) {
if (!$param_type->isFalsable() && $cased_method_id !== 'echo' && $cased_method_id !== 'print') {
if ($input_type->isFalse()) {
if (IssueBuffer::accepts(
new InvalidArgument(
'Argument ' . ($argument_offset + 1) . $method_identifier . ' cannot be false, ' .
'false value provided',
$arg_location,
$cased_method_id
),
$statements_analyzer->getSuppressedIssues()
)) {
// fall through
}
return null;
}
if ($input_type->isFalsable() && !$input_type->ignore_falsable_issues) {
if (IssueBuffer::accepts(
new PossiblyFalseArgument(
'Argument ' . ($argument_offset + 1) . $method_identifier . ' cannot be false, possibly ' .
@ -1133,6 +1145,7 @@ class ArgumentAnalyzer
// fall through
}
}
}
if (($type_match_found || $input_type->hasMixed())
&& !$function_param->by_ref

View File

@ -2106,6 +2106,15 @@ class FunctionCallTest extends TestCase
$a = max($b, $c);',
'error_message' => 'MixedAssignment'
],
'literalFalseArgument' => [
'<?php
function takesAString(string $s): void{
echo $s;
}
takesAString(false);',
'error_message' => 'InvalidArgument'
],
];
}
}