From 688367de38e887a19d5e3700c7559b8b9cf6369c Mon Sep 17 00:00:00 2001 From: orklah Date: Tue, 13 Jul 2021 00:06:36 +0200 Subject: [PATCH] Always emit InvalidArgument when the parameter is always false and not accepted --- .../Expression/Call/ArgumentAnalyzer.php | 43 ++++++++++++------- tests/FunctionCallTest.php | 9 ++++ 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php index 3e13920cf..7c510d14d 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php @@ -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 + } } } diff --git a/tests/FunctionCallTest.php b/tests/FunctionCallTest.php index 5c1936f9e..47135e083 100644 --- a/tests/FunctionCallTest.php +++ b/tests/FunctionCallTest.php @@ -2106,6 +2106,15 @@ class FunctionCallTest extends TestCase $a = max($b, $c);', 'error_message' => 'MixedAssignment' ], + 'literalFalseArgument' => [ + ' 'InvalidArgument' + ], ]; } }