From 05f2d01cb68a3cfa64a20738309e5493ab631aba Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Wed, 14 Oct 2020 21:35:46 -0400 Subject: [PATCH] Fix #4326 - Prevent later remapping of properties --- .../Fetch/InstancePropertyFetchAnalyzer.php | 4 +- tests/Template/ClassTemplateTest.php | 47 ++++++++++++++++++- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/InstancePropertyFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/InstancePropertyFetchAnalyzer.php index 49e058c66..583ddf31b 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/InstancePropertyFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/InstancePropertyFetchAnalyzer.php @@ -1004,9 +1004,7 @@ class InstancePropertyFetchAnalyzer $class_storage, $declaring_class_storage ); - } - - if ($lhs_type_part instanceof TGenericObject) { + } elseif ($lhs_type_part instanceof TGenericObject) { $class_property_type = self::localizePropertyType( $codebase, $class_property_type, diff --git a/tests/Template/ClassTemplateTest.php b/tests/Template/ClassTemplateTest.php index 20746c342..f788a6200 100644 --- a/tests/Template/ClassTemplateTest.php +++ b/tests/Template/ClassTemplateTest.php @@ -3005,7 +3005,7 @@ class ClassTemplateTest extends TestCase } }' ], - 'flippedParamsInside' => [ + 'flippedParamsMethodInside' => [ ' [ + 'flippedParamsMethodOutside' => [ ' [ + ' */ + public $traversable; + + /** + * @param Foo $flipped + * @return Traversable + */ + public function getFlippedTraversable(Foo $flipped): Traversable + { + return $flipped->traversable; + } + }' + ], + 'flippedParamsPropertyOutside' => [ + ' $flipped + * @return Traversable + */ + function getFlippedTraversable(Foo $flipped): Traversable { + return $flipped->traversable; + } + + /** + * @template A + * @template B + */ + abstract class Foo + { + /** @var Traversable */ + public $traversable; + }' + ], ]; }