mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Prevent infinite loops when analysing private functions that call each other
This commit is contained in:
parent
0018dee5e3
commit
72a4f148ff
@ -1228,9 +1228,19 @@ class CallChecker
|
||||
) {
|
||||
$method_id = $fq_class_name . '::' . strtolower($method_name);
|
||||
|
||||
$declaring_method_id = MethodChecker::getDeclaringMethodId($project_checker, $method_id);
|
||||
$declaring_method_id = (string) MethodChecker::getDeclaringMethodId($project_checker, $method_id);
|
||||
|
||||
$method_storage = $codebase->getMethodStorage((string)$declaring_method_id);
|
||||
if (isset($context->initialized_methods[$declaring_method_id])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($context->initialized_methods === null) {
|
||||
$context->initialized_methods = [];
|
||||
}
|
||||
|
||||
$context->initialized_methods[$declaring_method_id] = true;
|
||||
|
||||
$method_storage = $codebase->getMethodStorage($declaring_method_id);
|
||||
|
||||
$class_checker = $source->getSource();
|
||||
|
||||
|
@ -112,6 +112,13 @@ class Context
|
||||
*/
|
||||
public $collect_initializations = false;
|
||||
|
||||
/**
|
||||
* Stored to prevent re-analysing methods when checking for initialised properties
|
||||
*
|
||||
* @var array<string, bool>|null
|
||||
*/
|
||||
public $initialized_methods = null;
|
||||
|
||||
/**
|
||||
* @var array<string, Type\Union>
|
||||
*/
|
||||
|
@ -1143,6 +1143,30 @@ class PropertyTypeTest extends TestCase
|
||||
$a->foo = new B;',
|
||||
'error_message' => 'ImplicitToStringCast',
|
||||
],
|
||||
'noInfiniteLoop' => [
|
||||
'<?php
|
||||
class A {
|
||||
/** @var string */
|
||||
public $foo;
|
||||
|
||||
public function __construct() {
|
||||
$this->doThing();
|
||||
}
|
||||
|
||||
private function doThing(): void {
|
||||
if (rand(0, 1)) {
|
||||
$this->doOtherThing();
|
||||
}
|
||||
}
|
||||
|
||||
private function doOtherThing(): void {
|
||||
if (rand(0, 1)) {
|
||||
$this->doThing();
|
||||
}
|
||||
}
|
||||
}',
|
||||
'error_message' => 'PropertyNotSetInConstructor',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user