1
0
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:
Matthew Brown 2018-05-20 13:14:31 -04:00
parent cdcba6152d
commit a3e2b98f7c
2 changed files with 53 additions and 47 deletions

View File

@ -1437,53 +1437,6 @@ class CallChecker
$codebase->analyzer->incrementNonMixedCount($statements_checker->getCheckedFilePath()); $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( $param_type = TypeChecker::simplifyUnionType(
$project_checker->codebase, $project_checker->codebase,
$param_type $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 if ($type_match_found
&& !$param_type->isMixed() && !$param_type->isMixed()
&& !$param_type->from_docblock && !$param_type->from_docblock

View File

@ -906,6 +906,12 @@ class FunctionCallTest extends TestCase
takesIterableOfA([new B]); // should complain', takesIterableOfA([new B]); // should complain',
'error_message' => 'InvalidArgument', 'error_message' => 'InvalidArgument',
], ],
'putInvalidTypeMessagesFirst' => [
'<?php
$q = rand(0,1) ? new stdClass : false;
strlen($q);',
'error_message' => 'InvalidArgument',
],
]; ];
} }
} }