mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Check for indirect circular dependencies with stubbed parents.
This commit is contained in:
parent
9a064c04cf
commit
3510f55e31
@ -20,8 +20,10 @@ use function array_filter;
|
||||
use function array_intersect_key;
|
||||
use function array_keys;
|
||||
use function array_merge;
|
||||
use function array_splice;
|
||||
use function count;
|
||||
use function in_array;
|
||||
use function key;
|
||||
use function reset;
|
||||
use function strlen;
|
||||
use function strpos;
|
||||
@ -251,18 +253,26 @@ class Populator
|
||||
|
||||
if (isset($this->invalid_class_storages[$fq_classlike_name_lc])) {
|
||||
foreach ($this->invalid_class_storages[$fq_classlike_name_lc] as $dependency) {
|
||||
if (isset($dependency->dependent_classlikes[$fq_classlike_name_lc])) {
|
||||
if ($dependency->location) {
|
||||
IssueBuffer::maybeAdd(
|
||||
new CircularReference(
|
||||
'Circular reference discovered when loading ' . $dependency->name,
|
||||
$dependency->location
|
||||
)
|
||||
);
|
||||
}
|
||||
// Dependencies may not be fully set yet, so we have to loop through dependencies of dependencies
|
||||
$dependencies = [strtolower($dependency->name) => true];
|
||||
do {
|
||||
$current_dependency_name = key(array_splice($dependencies, 0, 1)); // Key shift
|
||||
$current_dependency = $storage_provider->get($current_dependency_name);
|
||||
$dependencies += $current_dependency->dependent_classlikes;
|
||||
|
||||
continue;
|
||||
}
|
||||
if (isset($current_dependency->dependent_classlikes[$fq_classlike_name_lc])) {
|
||||
if ($dependency->location) {
|
||||
IssueBuffer::maybeAdd(
|
||||
new CircularReference(
|
||||
'Circular reference discovered when loading ' . $dependency->name,
|
||||
$dependency->location
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
continue 2;
|
||||
}
|
||||
} while (!empty($dependencies));
|
||||
|
||||
$dependency->populated = false;
|
||||
unset($dependency->invalid_dependencies[$fq_classlike_name_lc]);
|
||||
|
@ -281,9 +281,7 @@ class StubTest extends TestCase
|
||||
$this->addFile(
|
||||
$file_path,
|
||||
'<?php
|
||||
class Foo extends Bar
|
||||
{
|
||||
}
|
||||
class Foo extends Baz {}
|
||||
'
|
||||
);
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
<?php
|
||||
|
||||
class Bar extends Foo {}
|
||||
|
||||
class Baz extends Bar {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user