From 4b8cadb5631fae0011ec68e0f28531be8e5fc63c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tomulik?= Date: Mon, 22 Nov 2021 23:32:05 +0100 Subject: [PATCH] attempt fixing issue #6973 --- .../Internal/Analyzer/MethodComparator.php | 28 ++++++++--------- tests/ReturnTypeTest.php | 30 ++++++++++++++++++- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/MethodComparator.php b/src/Psalm/Internal/Analyzer/MethodComparator.php index 15bc9f7cced..06cdfa7037b 100644 --- a/src/Psalm/Internal/Analyzer/MethodComparator.php +++ b/src/Psalm/Internal/Analyzer/MethodComparator.php @@ -980,23 +980,19 @@ private static function compareMethodDocblockReturnTypes( $implementer_called_class_name ); - if (isset( - $implementer_called_class_storage->template_extended_params[$implementer_classlike_storage->name] - )) { - self::transformTemplates( - $implementer_called_class_storage->template_extended_params, - $implementer_classlike_storage->name, - $implementer_method_storage_return_type, - $codebase - ); + self::transformTemplates( + $implementer_called_class_storage->template_extended_params, + $implementer_classlike_storage->name, + $implementer_method_storage_return_type, + $codebase + ); - self::transformTemplates( - $implementer_called_class_storage->template_extended_params, - $guide_class_name, - $guide_method_storage_return_type, - $codebase - ); - } + self::transformTemplates( + $implementer_called_class_storage->template_extended_params, + $guide_class_name, + $guide_method_storage_return_type, + $codebase + ); } // treat void as null when comparing against docblock implementer diff --git a/tests/ReturnTypeTest.php b/tests/ReturnTypeTest.php index 4aa65c197e7..4f0834a5097 100644 --- a/tests/ReturnTypeTest.php +++ b/tests/ReturnTypeTest.php @@ -1032,7 +1032,35 @@ public function __construct() { $this->value = 123; } }' - ] + ], + 'returnTypeOfAbstractMethodFromTemplatedTraitAndImplementationFromNonTemplatedTrait' => [ + 'value; + } + } + + /** @psalm-template T */ + trait GuideTrait { + /** @psalm-return T */ + abstract public function getValue(); + } + + class Test { + use ImplementorTrait; + + /** @template-use GuideTrait */ + use GuideTrait; + + public function __construct() { + $this->value = 123; + } + }' + ], ]; }