From 989c3ada2ed9f47cece73510fd9f8bec6f3ad4c1 Mon Sep 17 00:00:00 2001 From: adrew Date: Sat, 11 Dec 2021 22:51:18 +0300 Subject: [PATCH] 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 ac083fb1b..bf2b05532 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 @@ 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 diff --git a/tests/CallableTest.php b/tests/CallableTest.php index 83b42fff4..c0abc4459 100644 --- a/tests/CallableTest.php +++ b/tests/CallableTest.php @@ -63,6 +63,28 @@ class CallableTest extends TestCase 'error_levels' => [], '7.4', ], + 'inferArgFromClassContext' => [ + ' $a + $b);', + 'assertions' => [ + '$a' => 'int', + ], + 'error_levels' => [], + '7.4', + ], 'varReturnType' => [ '