1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Don’t add @psalm-pure for void-returning functions

This commit is contained in:
Matthew Brown 2020-08-23 13:58:34 -04:00
parent ef0486ce35
commit 6efaf474d4

View File

@ -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<empty, empty>'
) {
$manipulator->makePure();
}
}
if (!$context->collect_initializations