1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix #2166 - inherit twice from docblocks

This commit is contained in:
Brown 2019-09-25 12:02:50 -04:00
parent 267ae3a568
commit 2d621f185a
2 changed files with 81 additions and 3 deletions

View File

@ -262,9 +262,33 @@ class Populator
) {
foreach ($storage->methods as $method_name => $method_storage) {
if (isset($storage->overridden_method_ids[$method_name])) {
foreach ($storage->overridden_method_ids[$method_name] as $declaring_method_id) {
$overridden_method_ids = $storage->overridden_method_ids[$method_name];
$candidate_overridden_ids = null;
$declaring_class_storages = [];
foreach ($overridden_method_ids as $declaring_method_id) {
list($declaring_class, $declaring_method_name) = explode('::', $declaring_method_id);
$declaring_class_storage = $this->classlike_storage_provider->get($declaring_class);
$declaring_class_storage
= $declaring_class_storages[$declaring_class]
= $this->classlike_storage_provider->get($declaring_class);
if ($candidate_overridden_ids === null) {
$candidate_overridden_ids = $declaring_class_storage->overridden_method_ids[$method_name]
+ [$declaring_method_id => $declaring_method_id];
} else {
$candidate_overridden_ids = \array_intersect_key(
$candidate_overridden_ids,
$declaring_class_storage->overridden_method_ids[$method_name]
+ [$declaring_method_id => $declaring_method_id]
);
}
}
foreach ($overridden_method_ids as $declaring_method_id) {
list($declaring_class, $declaring_method_name) = explode('::', $declaring_method_id);
$declaring_class_storage = $declaring_class_storages[$declaring_class];
$declaring_method_storage = $declaring_class_storage->methods[strtolower($declaring_method_name)];
@ -291,7 +315,8 @@ class Populator
$method_storage->throws += $declaring_method_storage->throws;
}
if (count($storage->overridden_method_ids[$method_name]) === 1
if ((count($overridden_method_ids) === 1
|| $candidate_overridden_ids)
&& $method_storage->signature_return_type
&& !$method_storage->signature_return_type->isVoid()
&& ($method_storage->return_type === $method_storage->signature_return_type
@ -1015,6 +1040,13 @@ class Populator
} else {
$storage->overridden_method_ids[$method_name][$declaring_method_id] = $declaring_method_id;
}
if (isset($parent_storage->overridden_method_ids[$method_name])
&& isset($storage->overridden_method_ids[$method_name])
) {
$storage->overridden_method_ids[$method_name]
+= $parent_storage->overridden_method_ids[$method_name];
}
}
$aliased_method_names = [$method_name];

View File

@ -58,6 +58,52 @@ class DocblockInheritanceTest extends TestCase
return (new C)->foo($i);
}',
],
'inheritTwice' => [
'<?php
class Foo {
/**
* @return string[]
*/
public function aa() {
return [];
}
}
class Bar extends Foo {
public function aa() {
return [];
}
}
class Baz extends Bar {
public function aa() {
return [];
}
}'
],
'inheritTwiceWithArrayType' => [
'<?php
class Foo {
/**
* @return string[]
*/
public function aa() : array {
return [];
}
}
class Bar extends Foo {
public function aa() : array {
return [];
}
}
class Baz extends Bar {
public function aa() : array {
return [];
}
}'
],
];
}