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

allow calling mutation_free function inside a mutation_free context

This commit is contained in:
orklah 2021-12-30 22:29:36 +01:00
parent f9b3600a48
commit 392402cf6d
2 changed files with 22 additions and 1 deletions

View File

@ -1017,7 +1017,8 @@ class FunctionCallAnalyzer extends CallAnalyzer
if ((!$function_call_info->in_call_map
&& $function_call_info->function_storage
&& !$function_call_info->function_storage->pure)
&& !$function_call_info->function_storage->pure
&& !$function_call_info->function_storage->mutation_free)
|| ($callmap_function_pure === false)
) {
if ($context->mutation_free || $context->external_mutation_free) {

View File

@ -526,6 +526,26 @@ class ImmutableAnnotationTest extends TestCase
}
}',
],
'allowMutationFreeCallInMutationFreeContext' => [
'<?php
/**
* @psalm-mutation-free
*/
function getData(): array {
/** @var mixed $arr */
$arr = $GLOBALS["cachedData"] ?? [];
return is_array($arr) ? $arr : [];
}
/**
* @psalm-mutation-free
*/
function getDataItem(string $key): mixed {
return getData()[$key] ?? null;
}',
],
];
}