mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Allow pure functions/methods to be called and not destroy known properties
This commit is contained in:
parent
f20dc16295
commit
cfdfb9b64c
@ -568,7 +568,7 @@ class AssignmentAnalyzer
|
||||
$assign_value_type
|
||||
);
|
||||
} elseif ($assign_var instanceof PhpParser\Node\Expr\PropertyFetch) {
|
||||
if ($context->mutation_free) {
|
||||
if ($context->mutation_free && !$context->collect_mutations && !$context->collect_initializations) {
|
||||
if (IssueBuffer::accepts(
|
||||
new ImpurePropertyAssignment(
|
||||
'Cannot assign to a property from a mutation-free context',
|
||||
|
@ -567,13 +567,6 @@ class FunctionCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expressio
|
||||
}
|
||||
}
|
||||
|
||||
if (!$config->remember_property_assignments_after_call
|
||||
&& !$in_call_map
|
||||
&& !$context->collect_initializations
|
||||
) {
|
||||
$context->removeAllObjectVars();
|
||||
}
|
||||
|
||||
if ($stmt->name instanceof PhpParser\Node\Name &&
|
||||
($stmt->name->parts === ['get_class'] || $stmt->name->parts === ['gettype']) &&
|
||||
$stmt->args
|
||||
@ -623,7 +616,8 @@ class FunctionCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expressio
|
||||
&& !$context->collect_mutations
|
||||
&& ($context->mutation_free
|
||||
|| $context->external_mutation_free
|
||||
|| $codebase->find_unused_variables)
|
||||
|| $codebase->find_unused_variables
|
||||
|| !$config->remember_property_assignments_after_call)
|
||||
) {
|
||||
$callmap_function_pure = $function_id && $in_call_map
|
||||
? $codebase->functions->isCallMapFunctionPure($codebase, $function_id, $stmt->args)
|
||||
@ -644,6 +638,10 @@ class FunctionCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expressio
|
||||
// fall through
|
||||
}
|
||||
}
|
||||
|
||||
if (!$config->remember_property_assignments_after_call) {
|
||||
$context->removeAllObjectVars();
|
||||
}
|
||||
} elseif ($function_id
|
||||
&& (($function_storage && $function_storage->pure) || $callmap_function_pure === true)
|
||||
&& $codebase->find_unused_variables
|
||||
|
@ -185,7 +185,6 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
|
||||
}
|
||||
|
||||
$codebase = $statements_analyzer->getCodebase();
|
||||
$config = $codebase->config;
|
||||
|
||||
$non_existent_class_method_ids = [];
|
||||
$non_existent_interface_method_ids = [];
|
||||
@ -358,10 +357,6 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
|
||||
);
|
||||
}
|
||||
|
||||
if (!$config->remember_property_assignments_after_call && !$context->collect_initializations) {
|
||||
$context->removeAllObjectVars();
|
||||
}
|
||||
|
||||
// if we called a method on this nullable variable, remove the nullable status here
|
||||
// because any further calls must have worked
|
||||
if ($lhs_var_id
|
||||
@ -1272,6 +1267,13 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
|
||||
$stmt->pure = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$config->remember_property_assignments_after_call
|
||||
&& !$method_storage->mutation_free
|
||||
&& !$method_pure_compatible
|
||||
) {
|
||||
$context->removeAllObjectVars();
|
||||
}
|
||||
}
|
||||
|
||||
if ($method_storage->assertions) {
|
||||
|
Loading…
Reference in New Issue
Block a user