mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Always evaluate closures, even when passed as mixed call args
This commit is contained in:
parent
53ff05783c
commit
6e259bed03
@ -200,6 +200,16 @@ class MethodCallChecker extends \Psalm\Checker\Statements\Expression\CallChecker
|
||||
// fall through
|
||||
}
|
||||
|
||||
if (self::checkFunctionArguments(
|
||||
$statements_checker,
|
||||
$stmt->args,
|
||||
null,
|
||||
null,
|
||||
$context
|
||||
) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$return_type = Type::getMixed();
|
||||
break;
|
||||
}
|
||||
|
@ -466,6 +466,13 @@ class CallChecker
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// if it's a closure, we want to evaluate it anyway
|
||||
if ($arg->value instanceof PhpParser\Node\Expr\Closure) {
|
||||
if (ExpressionChecker::analyze($statements_checker, $arg->value, $context) === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($arg->value instanceof PhpParser\Node\Expr\PropertyFetch
|
||||
&& $arg->value->name instanceof PhpParser\Node\Identifier
|
||||
) {
|
||||
|
@ -220,6 +220,18 @@ class ValueTest extends TestCase
|
||||
$a();
|
||||
if ($i === 0) {}',
|
||||
],
|
||||
'incrementMixedCall' => [
|
||||
'<?php
|
||||
function foo($f) : void {
|
||||
$i = 0;
|
||||
$f->add(function() use (&$i) : void {
|
||||
if (rand(0, 1)) $i++;
|
||||
});
|
||||
if ($i === 0) {}
|
||||
}',
|
||||
'assertions' => [],
|
||||
'error_levels' => ['MissingParamType', 'MixedMethodCall'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user