mirror of
https://github.com/danog/psalm.git
synced 2024-12-02 09:37:59 +01:00
Fix errors in return types (#4189)
* FunctionLikeAnalyzer::verifyReturnType returns void * ArrayFunctionArgumentsAnalyzer::checkArgumentsMatch returns void * AssertionFinder::scrapeAssertions can't return null
This commit is contained in:
parent
a71af5a5e5
commit
2c1ff808bb
@ -1490,8 +1490,6 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
|
||||
|
||||
/**
|
||||
* @param array<PhpParser\Node\Stmt> $function_stmts
|
||||
*
|
||||
* @return false|null
|
||||
*/
|
||||
public function verifyReturnType(
|
||||
array $function_stmts,
|
||||
@ -1501,7 +1499,7 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
|
||||
?CodeLocation $return_type_location = null,
|
||||
bool $did_explicitly_return = false,
|
||||
bool $closure_inside_call = false
|
||||
) {
|
||||
): void {
|
||||
ReturnTypeAnalyzer::verifyReturnType(
|
||||
$this->function,
|
||||
$function_stmts,
|
||||
|
@ -37,7 +37,7 @@ class AssertionFinder
|
||||
/**
|
||||
* Gets all the type assertions in a conditional
|
||||
*
|
||||
* @return array<string, non-empty-list<non-empty-list<string>>>|null
|
||||
* @return array<string, non-empty-list<non-empty-list<string>>>
|
||||
*/
|
||||
public static function scrapeAssertions(
|
||||
PhpParser\Node\Expr $conditional,
|
||||
@ -47,7 +47,7 @@ class AssertionFinder
|
||||
bool $inside_negation = false,
|
||||
bool $cache = true,
|
||||
bool $inside_conditional = true
|
||||
) {
|
||||
): array {
|
||||
$if_types = [];
|
||||
|
||||
if ($conditional instanceof PhpParser\Node\Expr\Instanceof_) {
|
||||
@ -195,10 +195,6 @@ class AssertionFinder
|
||||
}
|
||||
}
|
||||
|
||||
if ($expr_assertions === null) {
|
||||
throw new \UnexpectedValueException('Assertions should be set');
|
||||
}
|
||||
|
||||
if (count($expr_assertions) !== 1) {
|
||||
return [];
|
||||
}
|
||||
@ -699,10 +695,6 @@ class AssertionFinder
|
||||
}
|
||||
}
|
||||
|
||||
if ($base_assertions === null) {
|
||||
throw new \UnexpectedValueException('Assertions should be set');
|
||||
}
|
||||
|
||||
$if_types = $base_assertions;
|
||||
}
|
||||
}
|
||||
@ -820,10 +812,6 @@ class AssertionFinder
|
||||
}
|
||||
}
|
||||
|
||||
if ($base_assertions === null) {
|
||||
throw new \UnexpectedValueException('Assertions should be set');
|
||||
}
|
||||
|
||||
$notif_types = $base_assertions;
|
||||
|
||||
if (count($notif_types) === 1) {
|
||||
@ -1338,10 +1326,6 @@ class AssertionFinder
|
||||
}
|
||||
}
|
||||
|
||||
if ($base_assertions === null) {
|
||||
throw new \UnexpectedValueException('Assertions should be set');
|
||||
}
|
||||
|
||||
$notif_types = $base_assertions;
|
||||
|
||||
if (count($notif_types) === 1) {
|
||||
@ -1448,10 +1432,6 @@ class AssertionFinder
|
||||
}
|
||||
}
|
||||
|
||||
if ($base_assertions === null) {
|
||||
throw new \UnexpectedValueException('Assertions should be set');
|
||||
}
|
||||
|
||||
$notif_types = $base_assertions;
|
||||
|
||||
if (count($notif_types) === 1) {
|
||||
|
@ -703,16 +703,13 @@ class ArgumentsAnalyzer
|
||||
}
|
||||
}
|
||||
|
||||
if (ArrayFunctionArgumentsAnalyzer::checkArgumentsMatch(
|
||||
ArrayFunctionArgumentsAnalyzer::checkArgumentsMatch(
|
||||
$statements_analyzer,
|
||||
$context,
|
||||
$args,
|
||||
$method_id,
|
||||
$context->check_functions
|
||||
) === false
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -44,7 +44,6 @@ class ArrayFunctionArgumentsAnalyzer
|
||||
{
|
||||
/**
|
||||
* @param array<int, PhpParser\Node\Arg> $args
|
||||
* @return false|null
|
||||
*/
|
||||
public static function checkArgumentsMatch(
|
||||
StatementsAnalyzer $statements_analyzer,
|
||||
@ -52,7 +51,7 @@ class ArrayFunctionArgumentsAnalyzer
|
||||
array $args,
|
||||
string $method_id,
|
||||
bool $check_functions
|
||||
) {
|
||||
): void {
|
||||
$closure_index = $method_id === 'array_map' ? 0 : 1;
|
||||
|
||||
$array_arg_types = [];
|
||||
|
@ -201,7 +201,6 @@ class Algebra
|
||||
}
|
||||
}
|
||||
|
||||
if ($assertions !== null) {
|
||||
$clauses = [];
|
||||
|
||||
foreach ($assertions as $var => $anded_types) {
|
||||
@ -232,7 +231,6 @@ class Algebra
|
||||
|
||||
return self::negateFormula($clauses);
|
||||
}
|
||||
}
|
||||
|
||||
if ($conditional->expr instanceof PhpParser\Node\Expr\BinaryOp\BooleanAnd) {
|
||||
$and_expr = new PhpParser\Node\Expr\BinaryOp\BooleanOr(
|
||||
|
Loading…
Reference in New Issue
Block a user