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:
parent
e93b37a225
commit
688367de38
@ -1115,22 +1115,35 @@ class ArgumentAnalyzer
|
||||
}
|
||||
}
|
||||
|
||||
if ($input_type->isFalsable()
|
||||
&& !$param_type->hasBool()
|
||||
&& !$param_type->hasScalar()
|
||||
&& !$input_type->ignore_falsable_issues
|
||||
&& $cased_method_id !== 'echo'
|
||||
) {
|
||||
if (IssueBuffer::accepts(
|
||||
new PossiblyFalseArgument(
|
||||
'Argument ' . ($argument_offset + 1) . $method_identifier . ' cannot be false, possibly ' .
|
||||
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
|
||||
$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 ' .
|
||||
'false value provided',
|
||||
$arg_location,
|
||||
$cased_method_id
|
||||
),
|
||||
$statements_analyzer->getSuppressedIssues()
|
||||
)) {
|
||||
// fall through
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user