diff --git a/src/Psalm/Internal/Analyzer/ClassAnalyzer.php b/src/Psalm/Internal/Analyzer/ClassAnalyzer.php index 2e21a870e59..e878baf77f3 100644 --- a/src/Psalm/Internal/Analyzer/ClassAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ClassAnalyzer.php @@ -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 @@ -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 diff --git a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php index 2566009bcba..d6f1d7eb306 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php @@ -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, @@ -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, diff --git a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php index c2b5133e94b..5e7eae3ba7a 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php @@ -1420,6 +1420,7 @@ public function verifyReturnType( $this, $return_type, $fq_class_name, + $fq_class_name, $return_type_location, [], $did_explicitly_return, diff --git a/tests/ReturnTypeTest.php b/tests/ReturnTypeTest.php index 1241c9bd110..53be10b286e 100644 --- a/tests/ReturnTypeTest.php +++ b/tests/ReturnTypeTest.php @@ -247,6 +247,27 @@ class B extends A { '$bees' => 'array', ], ], + 'extendsStaticConstReturnType' => [ + ' [ '