Skip to content
Permalink
Browse files

Allow pure functions/methods to be called and not destroy known prope…

…rties
  • Loading branch information...
muglug committed Aug 31, 2019
1 parent f20dc16 commit cfdfb9b64c8ae73b9edc9431a2b9354b775d0aac
@@ -568,7 +568,7 @@ public static function analyze(
$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 @@ public static function analyze(
}
}
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 @@ public static function analyze(
&& !$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 @@ public static function analyze(
// 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 @@ public static function analyze(
}
$codebase = $statements_analyzer->getCodebase();
$config = $codebase->config;
$non_existent_class_method_ids = [];
$non_existent_interface_method_ids = [];
@@ -358,10 +357,6 @@ public static function analyze(
);
}
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 @@ function (PhpParser\Node\Arg $arg) {
$stmt->pure = true;
}
}
if (!$config->remember_property_assignments_after_call
&& !$method_storage->mutation_free
&& !$method_pure_compatible
) {
$context->removeAllObjectVars();
}
}
if ($method_storage->assertions) {

0 comments on commit cfdfb9b

Please sign in to comment.
You can’t perform that action at this time.