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:
parent
f9b3600a48
commit
392402cf6d
@ -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) {
|
||||
|
@ -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;
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user