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:
parent
e93b37a225
commit
688367de38
@ -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
|
||||||
|
@ -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'
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user