From 6efaf474d4d6ba0520ef7955c021a23f4d14033c Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Sun, 23 Aug 2020 13:58:34 -0400 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20add=20@psalm-pure=20for=20void-?= =?UTF-8?q?returning=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Analyzer/FunctionLikeAnalyzer.php | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php index bd816df22..b4c8dcbd6 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php @@ -593,7 +593,31 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer $this->function ); - $manipulator->makePure(); + $yield_types = []; + + $inferred_return_types = ReturnTypeCollector::getReturnTypes( + $codebase, + $type_provider, + $function_stmts, + $yield_types, + true + ); + + $inferred_return_type = $inferred_return_types + ? \Psalm\Type::combineUnionTypeArray( + $inferred_return_types, + $codebase + ) + : null; + + if ($inferred_return_type + && !$inferred_return_type->isVoid() + && !$inferred_return_type->isFalse() + && !$inferred_return_type->isTrue() + && !$inferred_return_type->getId() !== 'array' + ) { + $manipulator->makePure(); + } } if (!$context->collect_initializations