mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Fix #743 - put InvalidArgument messages before PossiblyFalseArgument
This commit is contained in:
parent
cdcba6152d
commit
a3e2b98f7c
@ -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
|
||||
|
@ -906,6 +906,12 @@ class FunctionCallTest extends TestCase
|
||||
takesIterableOfA([new B]); // should complain',
|
||||
'error_message' => 'InvalidArgument',
|
||||
],
|
||||
'putInvalidTypeMessagesFirst' => [
|
||||
'<?php
|
||||
$q = rand(0,1) ? new stdClass : false;
|
||||
strlen($q);',
|
||||
'error_message' => 'InvalidArgument',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user