Skip to content

Commit

Permalink
Fix #2751 - allow static methods to inherit class templates
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Feb 5, 2020
1 parent bbdb125 commit 50fc50f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/Psalm/Internal/Visitor/ReflectorVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2379,9 +2379,7 @@ function (FunctionLikeParameter $p) {
);
}

$class_template_types = !$stmt instanceof PhpParser\Node\Stmt\ClassMethod || !$stmt->isStatic()
? $this->class_template_types
: [];
$class_template_types = $this->class_template_types;

foreach ($docblock_info->params_out as $docblock_param_out) {
$param_name = substr($docblock_param_out['name'], 1);
Expand Down
31 changes: 31 additions & 0 deletions tests/Template/ClassTemplateExtendsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2857,6 +2857,37 @@ protected function doView() {
}
}'
],
'allowStaticMethodClassTemplates' => [
'<?php
namespace A;
class DeliveryTimeAggregated {}
/**
* @template T of object
*/
interface ReplayMessageInterface
{
/**
* @return class-string<T>
*/
public static function messageName(): string;
}
/**
* @template-implements ReplayMessageInterface<DeliveryTimeAggregated>
*/
class ReplayDeliveryTimeAggregated implements ReplayMessageInterface
{
/**
* @return class-string<DeliveryTimeAggregated>
*/
public static function messageName(): string
{
return DeliveryTimeAggregated::class;
}
}'
],
];
}

Expand Down

0 comments on commit 50fc50f

Please sign in to comment.