From d9ad8b420ed322556ab02847ec7ed20adf3e6fdf Mon Sep 17 00:00:00 2001 From: andrew Date: Fri, 7 Apr 2023 14:16:41 +0300 Subject: [PATCH] Ignore specific callables (callable-array, callable-string) in the HighOrderFunctionArgHandler --- .../Call/HighOrderFunctionArgHandler.php | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/HighOrderFunctionArgHandler.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/HighOrderFunctionArgHandler.php index 4311882c9..3d1a51c4e 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/HighOrderFunctionArgHandler.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/HighOrderFunctionArgHandler.php @@ -154,7 +154,7 @@ final class HighOrderFunctionArgHandler StatementsAnalyzer $statements_analyzer, FunctionLikeParameter $container_param ): ?HighOrderFunctionArgInfo { - if (!$container_param->type || !$container_param->type->hasCallableType()) { + if (!self::isSupported($container_param)) { return null; } @@ -281,6 +281,28 @@ final class HighOrderFunctionArgHandler return null; } + private static function isSupported(FunctionLikeParameter $container_param): bool + { + if (!$container_param->type || !$container_param->type->hasCallableType()) { + return false; + } + + foreach ($container_param->type->getAtomicTypes() as $a) { + if (($a instanceof TClosure || $a instanceof TCallable) && !$a->params) { + return false; + } + + if ($a instanceof Type\Atomic\TCallableArray || + $a instanceof Type\Atomic\TCallableString || + $a instanceof Type\Atomic\TCallableKeyedArray + ) { + return false; + } + } + + return true; + } + private static function fromLiteralString( Union $constant, StatementsAnalyzer $statements_analyzer