1
0
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:
Matt Brown 2018-05-08 18:11:10 -04:00
parent 53ff05783c
commit 6e259bed03
3 changed files with 29 additions and 0 deletions

View File

@ -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;
}

View File

@ -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
) {

View File

@ -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'],
],
];
}