1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix type inference of closure params

This commit is contained in:
adrew 2021-12-11 22:51:18 +03:00
parent 76bb8bc655
commit 989c3ada2e
3 changed files with 23 additions and 5 deletions

View File

@ -181,8 +181,6 @@ class ArgumentsAnalyzer
if (($arg->value instanceof PhpParser\Node\Expr\Closure
|| $arg->value instanceof PhpParser\Node\Expr\ArrowFunction)
&& $template_result
&& $template_result->lower_bounds
&& $param
&& !$arg->value->getDocComment()
) {
@ -191,7 +189,7 @@ class ArgumentsAnalyzer
$args,
$method_id,
$context,
$template_result,
$template_result ?? new TemplateResult([], []),
$argument_offset,
$arg,
$param

View File

@ -63,6 +63,28 @@ class CallableTest extends TestCase
'error_levels' => [],
'7.4',
],
'inferArgFromClassContext' => [
'<?php
final class Calc
{
/**
* @param Closure(int, int): int $_fn
*/
public function __invoke(Closure $_fn): void
{
return $_fn(42, 42);
}
}
$calc = new Calc();
$a = $calc(fn($a, $b) => $a + $b);',
'assertions' => [
'$a' => 'int',
],
'error_levels' => [],
'7.4',
],
'varReturnType' => [
'<?php
$add_one = function(int $a) : int {

View File

@ -1377,8 +1377,6 @@ class FunctionCallTest extends TestCase
'<?php
/**
* @param string[] $ids
* @psalm-suppress MissingClosureReturnType
* @psalm-suppress MixedArgumentTypeCoercion
*/
function(array $ids): array {
return \preg_replace_callback(