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:
parent
76bb8bc655
commit
989c3ada2e
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user