1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +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 committed by Daniil Gentili
parent 5656591962
commit 2e2f0a2386
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7

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