Skip to content
Permalink
Browse files

Fix erroneous marking of external-mutation-free method as unused

  • Loading branch information...
muglug committed Aug 31, 2019
1 parent 900cfc0 commit 4a38ab165fc83bd69e6a99839a9e70a819aeb901
@@ -1250,7 +1250,8 @@ function (PhpParser\Node\Arg $arg) {
// fall through
}
} elseif (($method_storage->mutation_free
|| $method_pure_compatible)
|| ($method_storage->external_mutation_free
&& (isset($stmt->var->external_mutation_free) || isset($stmt->var->pure))))
&& $codebase->find_unused_variables
&& !$context->inside_conditional
&& !$context->inside_unset
@@ -475,6 +475,8 @@ public static function analyze(
}
if ($storage->external_mutation_free) {
/** @psalm-suppress UndefinedPropertyAssignment */
$stmt->external_mutation_free = true;
$stmt->inferredType->external_mutation_free = true;
}
}
@@ -46,7 +46,7 @@ private function checkNonTrivialExpr(PhpParser\Node\Expr $node)
return false;
}
if ($node instanceof PhpParser\Node\Expr\New_ && !empty($node->inferredType->external_mutation_free)) {
if ($node instanceof PhpParser\Node\Expr\New_ && isset($node->external_mutation_free)) {
return false;
}
@@ -584,6 +584,28 @@ function inc(array $arr) : array {
return $arr;
}'
],
'pureFunctionUsesMethodBeforeReturning' => [
'<?php
/** @psalm-external-mutation-free */
class Counter {
private int $count = 0;
public function __construct(int $count) {
$this->count = $count;
}
public function increment() : void {
$this->count++;
}
}
/** @psalm-pure */
function makesACounter(int $i) : Counter {
$c = new Counter($i);
$c->increment();
return $c;
}',
],
];
}

0 comments on commit 4a38ab1

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