diff --git a/src/Psalm/Checker/Statements/Expression/CallChecker.php b/src/Psalm/Checker/Statements/Expression/CallChecker.php index aa9ab8404..f07c6d9bf 100644 --- a/src/Psalm/Checker/Statements/Expression/CallChecker.php +++ b/src/Psalm/Checker/Statements/Expression/CallChecker.php @@ -1437,53 +1437,6 @@ class CallChecker $codebase->analyzer->incrementNonMixedCount($statements_checker->getCheckedFilePath()); - if (!$param_type->isNullable() && $cased_method_id !== 'echo') { - if ($input_type->isNull()) { - if (IssueBuffer::accepts( - new NullArgument( - 'Argument ' . ($argument_offset + 1) . $method_identifier . ' cannot be null, ' . - 'null value provided', - $code_location - ), - $statements_checker->getSuppressedIssues() - )) { - return false; - } - - return null; - } - - if ($input_type->isNullable() && !$input_type->ignore_nullable_issues) { - if (IssueBuffer::accepts( - new PossiblyNullArgument( - 'Argument ' . ($argument_offset + 1) . $method_identifier . ' cannot be null, possibly ' . - 'null value provided', - $code_location - ), - $statements_checker->getSuppressedIssues() - )) { - return false; - } - } - } - - if ($input_type->isFalsable() - && !$param_type->hasBool() - && !$param_type->hasScalar() - && !$input_type->ignore_falsable_issues - ) { - if (IssueBuffer::accepts( - new PossiblyFalseArgument( - 'Argument ' . ($argument_offset + 1) . $method_identifier . ' cannot be false, possibly ' . - 'false value provided', - $code_location - ), - $statements_checker->getSuppressedIssues() - )) { - return false; - } - } - $param_type = TypeChecker::simplifyUnionType( $project_checker->codebase, $param_type @@ -1704,6 +1657,53 @@ class CallChecker } } + if (!$param_type->isNullable() && $cased_method_id !== 'echo') { + if ($input_type->isNull()) { + if (IssueBuffer::accepts( + new NullArgument( + 'Argument ' . ($argument_offset + 1) . $method_identifier . ' cannot be null, ' . + 'null value provided', + $code_location + ), + $statements_checker->getSuppressedIssues() + )) { + return false; + } + + return null; + } + + if ($input_type->isNullable() && !$input_type->ignore_nullable_issues) { + if (IssueBuffer::accepts( + new PossiblyNullArgument( + 'Argument ' . ($argument_offset + 1) . $method_identifier . ' cannot be null, possibly ' . + 'null value provided', + $code_location + ), + $statements_checker->getSuppressedIssues() + )) { + return false; + } + } + } + + if ($input_type->isFalsable() + && !$param_type->hasBool() + && !$param_type->hasScalar() + && !$input_type->ignore_falsable_issues + ) { + if (IssueBuffer::accepts( + new PossiblyFalseArgument( + 'Argument ' . ($argument_offset + 1) . $method_identifier . ' cannot be false, possibly ' . + 'false value provided', + $code_location + ), + $statements_checker->getSuppressedIssues() + )) { + return false; + } + } + if ($type_match_found && !$param_type->isMixed() && !$param_type->from_docblock diff --git a/tests/FunctionCallTest.php b/tests/FunctionCallTest.php index e7cde8e16..6b07f81e2 100644 --- a/tests/FunctionCallTest.php +++ b/tests/FunctionCallTest.php @@ -906,6 +906,12 @@ class FunctionCallTest extends TestCase takesIterableOfA([new B]); // should complain', 'error_message' => 'InvalidArgument', ], + 'putInvalidTypeMessagesFirst' => [ + ' 'InvalidArgument', + ], ]; } }