Skip to content

Commit

Permalink
Use better way to determine which signture to use
Browse files Browse the repository at this point in the history
Fixes #4524
  • Loading branch information
muglug committed Nov 12, 2020
1 parent 2f7bf2a commit b7551e7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/Psalm/Internal/Codebase/Methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -762,9 +762,7 @@ public function getMethodReturnType(

$self_class = $overridden_class_storage->name;

if ($candidate_type
&& $source_analyzer
) {
if ($candidate_type && $source_analyzer && !$candidate_type->isMixed()) {
$old_contained_by_new = UnionTypeComparator::isContainedBy(
$source_analyzer->getCodebase(),
$candidate_type,
Expand Down
7 changes: 6 additions & 1 deletion src/Psalm/Internal/Codebase/Populator.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,12 @@ private function populateOverriddenMethods(

if ($declaring_method_storage->has_docblock_param_types
&& !$method_storage->has_docblock_param_types
&& !isset($storage->documenting_method_ids[$method_name])
&& (!isset($storage->documenting_method_ids[$method_name])
|| \in_array(
$storage->documenting_method_ids[$method_name]->fq_class_name,
$declaring_class_storage->parent_interfaces
)
)
) {
$storage->documenting_method_ids[$method_name] = $declaring_method_id;
}
Expand Down
32 changes: 32 additions & 0 deletions tests/Template/ClassTemplateExtendsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4561,6 +4561,38 @@ public function valuesToSave(): array
}
}'
],
'inheritCorrectParams' => [
'<?php
interface ToBeIgnored
{
/**
* @param mixed $value
* @return mixed
*/
public static function of($value);
}
interface ToBeUsed extends ToBeIgnored
{
/**
* @template U
* @param U $value
* @return U
*/
public static function of($value);
}
interface ExtendsToBeUsed extends ToBeUsed {}
class Foo implements ExtendsToBeUsed {
/** @psalm-suppress InvalidReturnType */
public static function of($value) {}
}
function bar(Foo $f, string $s) : string {
return $f::of($s);
}'
],
];
}

Expand Down

0 comments on commit b7551e7

Please sign in to comment.