From 989c3ada2ed9f47cece73510fd9f8bec6f3ad4c1 Mon Sep 17 00:00:00 2001 From: adrew Date: Sat, 11 Dec 2021 22:51:18 +0300 Subject: [PATCH 1/2] Fix type inference of closure params --- .../Expression/Call/ArgumentsAnalyzer.php | 4 +--- tests/CallableTest.php | 22 +++++++++++++++++++ tests/FunctionCallTest.php | 2 -- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php index ac083fb1bfa..bf2b05532af 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php @@ -181,8 +181,6 @@ public static function analyze( 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 @@ public static function analyze( $args, $method_id, $context, - $template_result, + $template_result ?? new TemplateResult([], []), $argument_offset, $arg, $param diff --git a/tests/CallableTest.php b/tests/CallableTest.php index 83b42fff446..c0abc4459d1 100644 --- a/tests/CallableTest.php +++ b/tests/CallableTest.php @@ -63,6 +63,28 @@ function(string $a) { 'error_levels' => [], '7.4', ], + 'inferArgFromClassContext' => [ + ' $a + $b);', + 'assertions' => [ + '$a' => 'int', + ], + 'error_levels' => [], + '7.4', + ], 'varReturnType' => [ ' Date: Sat, 11 Dec 2021 22:51:18 +0300 Subject: [PATCH 2/2] Fix type inference of closure params --- tests/CallableTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CallableTest.php b/tests/CallableTest.php index c0abc4459d1..1b84ad82191 100644 --- a/tests/CallableTest.php +++ b/tests/CallableTest.php @@ -70,7 +70,7 @@ final class Calc /** * @param Closure(int, int): int $_fn */ - public function __invoke(Closure $_fn): void + public function __invoke(Closure $_fn): int { return $_fn(42, 42); }