From a089d8bd58875a3e9c9bd82285289915d534d9e0 Mon Sep 17 00:00:00 2001 From: Brown Date: Sun, 3 May 2020 20:42:00 -0400 Subject: [PATCH] Fix #3296 - propagate final flag to static calls in return types --- .../Call/MethodCallReturnTypeFetcher.php | 6 +++- tests/Template/ClassTemplateExtendsTest.php | 30 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallReturnTypeFetcher.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallReturnTypeFetcher.php index c20e07b69b5..37210bd1613 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallReturnTypeFetcher.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallReturnTypeFetcher.php @@ -173,7 +173,11 @@ public static function fetch( $return_type_candidate, $self_fq_class_name, $static_type, - $class_storage->parent_class + $class_storage->parent_class, + true, + false, + $static_type instanceof Type\Atomic\TNamedObject + && $codebase->classlike_storage_provider->get($static_type->value)->final ); if ($codebase->taint) { diff --git a/tests/Template/ClassTemplateExtendsTest.php b/tests/Template/ClassTemplateExtendsTest.php index 1e3f1b2720c..a4049b7c268 100644 --- a/tests/Template/ClassTemplateExtendsTest.php +++ b/tests/Template/ClassTemplateExtendsTest.php @@ -4001,6 +4001,36 @@ public function foo($b): bool { } }' ], + 'finalOverridesStatic' => [ + ' + */ + public function getTypes() { + return new Collection(new static); + } + } + + final class Cheese extends Food {} + + /** + * @return Collection + */ + function test(Cheese $cheese): Collection { + return $cheese->getTypes(); + }' + ], ]; }