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

Don’t complain about mutating call when it was inferred during reflection

This commit is contained in:
Matthew Brown 2019-09-08 10:36:57 -04:00
parent d27935d109
commit 4cac8cd70f
3 changed files with 15 additions and 2 deletions

View File

@ -413,11 +413,18 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer implements Statements
$context->pure = true;
}
if ($storage->mutation_free && $cased_method_id && !strpos($cased_method_id, '__construct')) {
if ($storage->mutation_free
&& $cased_method_id
&& !strpos($cased_method_id, '__construct')
&& !($storage instanceof MethodStorage && $storage->mutation_free_inferred)
) {
$context->mutation_free = true;
}
if ($storage instanceof MethodStorage && $storage->external_mutation_free) {
if ($storage instanceof MethodStorage
&& $storage->external_mutation_free
&& !$storage->mutation_free_inferred
) {
$context->external_mutation_free = true;
}

View File

@ -1807,6 +1807,7 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
) {
$storage->mutation_free = true;
$storage->external_mutation_free = true;
$storage->mutation_free_inferred = true;
} elseif (strpos($stmt->name->name, 'assert') === 0) {
$var_assertions = [];

View File

@ -58,6 +58,11 @@ class MethodStorage extends FunctionLikeStorage
*/
public $external_mutation_free = false;
/**
* @var bool
*/
public $mutation_free_inferred = false;
/**
* @var ?array<string, bool>
*/