mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Memoize private inferred mutation-free methods (#4832)
This commit is contained in:
parent
e393a45ac7
commit
d8d6811ed4
@ -2,6 +2,7 @@
|
||||
namespace Psalm\Internal\Analyzer\Statements\Expression\Call\Method;
|
||||
|
||||
use PhpParser;
|
||||
use Psalm\Internal\Analyzer\ClassLikeAnalyzer;
|
||||
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
||||
use Psalm\Codebase;
|
||||
use Psalm\CodeLocation;
|
||||
@ -79,7 +80,8 @@ class MethodCallPurityAnalyzer
|
||||
) {
|
||||
if ($method_storage->mutation_free
|
||||
&& (!$method_storage->mutation_free_inferred
|
||||
|| $method_storage->final)
|
||||
|| $method_storage->final
|
||||
|| $method_storage->visibility === ClassLikeAnalyzer::VISIBILITY_PRIVATE)
|
||||
&& ($method_storage->immutable || $config->remember_property_assignments_after_call)
|
||||
) {
|
||||
if ($context->inside_conditional
|
||||
|
@ -857,6 +857,27 @@ class MethodCallTest extends TestCase
|
||||
printInt($obj->getInt());
|
||||
}',
|
||||
],
|
||||
'privateInferredMutationFreeMethodCallMemoize' => [
|
||||
'<?php
|
||||
class PropertyClass {
|
||||
public function test() : void {
|
||||
echo "test";
|
||||
}
|
||||
}
|
||||
class SomeClass {
|
||||
private ?PropertyClass $property = null;
|
||||
|
||||
private function getProperty(): ?PropertyClass {
|
||||
return $this->property;
|
||||
}
|
||||
|
||||
public function test(int $int): void {
|
||||
if ($this->getProperty() !== null) {
|
||||
$this->getProperty()->test();
|
||||
}
|
||||
}
|
||||
}',
|
||||
],
|
||||
'inferredFinalMethod' => [
|
||||
'<?php
|
||||
class PropertyClass {
|
||||
|
Loading…
x
Reference in New Issue
Block a user