Skip to content

Commit

Permalink
Merge pull request #7366 from Patrick-Remy/fix/return-type-static
Browse files Browse the repository at this point in the history
fix: pass static class name to ReturnTypeAnalyzer
  • Loading branch information
orklah committed Jan 10, 2022
2 parents 549c02d + a555543 commit e4040e9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Psalm/Internal/Analyzer/ClassAnalyzer.php
Expand Up @@ -1942,6 +1942,7 @@ public static function analyzeClassMethodReturnType(
$method_analyzer,
$interface_return_type,
$interface_class,
$original_fq_classlike_name,
$interface_return_type_location,
[$analyzed_method_id->__toString()],
$did_explicitly_return
Expand Down Expand Up @@ -1969,6 +1970,7 @@ function ($method_id) {
$method_analyzer,
$return_type,
$fq_classlike_name,
$original_fq_classlike_name,
$return_type_location,
$overridden_method_ids,
$did_explicitly_return
Expand Down
Expand Up @@ -80,6 +80,7 @@ public static function verifyReturnType(
FunctionLikeAnalyzer $function_like_analyzer,
?Union $return_type = null,
?string $fq_class_name = null,
?string $static_fq_class_name = null,
?CodeLocation $return_type_location = null,
array $compatible_method_ids = [],
bool $did_explicitly_return = false,
Expand Down Expand Up @@ -425,7 +426,7 @@ static function (Union $union_type): bool {
$codebase,
$return_type,
$self_fq_class_name,
$self_fq_class_name,
$static_fq_class_name,
$parent_class,
true,
true,
Expand Down
1 change: 1 addition & 0 deletions src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php
Expand Up @@ -1420,6 +1420,7 @@ public function verifyReturnType(
$this,
$return_type,
$fq_class_name,
$fq_class_name,
$return_type_location,
[],
$did_explicitly_return,
Expand Down
21 changes: 21 additions & 0 deletions tests/ReturnTypeTest.php
Expand Up @@ -247,6 +247,27 @@ class B extends A {
'$bees' => 'array<int, B>',
],
],
'extendsStaticConstReturnType' => [
'<?php
class A {
/** @var int */
private const FOO = 1;
/** @return static::FOO */
public function getFoo() {
return self::FOO;
}
}
class B extends A {
/** @var int */
private const FOO = 2;
public function getFoo() {
return self::FOO;
}
}',
],
'issetReturnType' => [
'<?php
/**
Expand Down

0 comments on commit e4040e9

Please sign in to comment.