1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 12:55:26 +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() if (!$param_type->isFalsable() && $cased_method_id !== 'echo' && $cased_method_id !== 'print') {
&& !$param_type->hasBool() if ($input_type->isFalse()) {
&& !$param_type->hasScalar() if (IssueBuffer::accepts(
&& !$input_type->ignore_falsable_issues new InvalidArgument(
&& $cased_method_id !== 'echo' '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( if (IssueBuffer::accepts(
new PossiblyFalseArgument( new PossiblyFalseArgument(
'Argument ' . ($argument_offset + 1) . $method_identifier . ' cannot be false, possibly ' . 'Argument ' . ($argument_offset + 1) . $method_identifier . ' cannot be false, possibly ' .
@ -1133,6 +1145,7 @@ class ArgumentAnalyzer
// fall through // fall through
} }
} }
}
if (($type_match_found || $input_type->hasMixed()) if (($type_match_found || $input_type->hasMixed())
&& !$function_param->by_ref && !$function_param->by_ref

View File

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