From 0456ef82a5cbdde43630513efa287c400680216c Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 6 Apr 2023 10:43:50 +0300 Subject: [PATCH] Prevent callable arg type enhancement for simple callable --- .../Expression/Call/HighOrderFunctionArgHandler.php | 4 ++++ .../Statements/Expression/Call/HighOrderFunctionArgInfo.php | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/HighOrderFunctionArgHandler.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/HighOrderFunctionArgHandler.php index a671aa53a..53a2cd282 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/HighOrderFunctionArgHandler.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/HighOrderFunctionArgHandler.php @@ -78,6 +78,10 @@ final class HighOrderFunctionArgHandler HighOrderFunctionArgInfo $high_order_callable_info, ?TemplateResult $high_order_template_result ): void { + if ($high_order_callable_info->getType() === HighOrderFunctionArgInfo::TYPE_CALLABLE) { + return; + } + $statements_analyzer->node_data->setType($arg_expr, TemplateInferredTypeReplacer::replace( $high_order_callable_info->getFunctionType(), $high_order_template_result ?? new TemplateResult([], []), diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/HighOrderFunctionArgInfo.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/HighOrderFunctionArgInfo.php index 99b400c9b..526e6ee11 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/HighOrderFunctionArgInfo.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/HighOrderFunctionArgInfo.php @@ -54,6 +54,11 @@ final class HighOrderFunctionArgInfo return new TemplateResult($templates, []); } + public function getType(): string + { + return $this->type; + } + public function getFunctionType(): Union { switch ($this->type) {