From 8ccc19697afa69991b7c317beb922162a996ed81 Mon Sep 17 00:00:00 2001 From: Ivan Sidorov Date: Wed, 27 Mar 2024 07:41:22 +0000 Subject: [PATCH] Part 6. Fix mixin collisions on properties --- .../Fetch/AtomicPropertyFetchAnalyzer.php | 11 ++++ tests/MixinsDeepTest.php | 50 +++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php index d483af45d05..466479de3bf 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php @@ -1258,6 +1258,9 @@ private static function handleNonExistentProperty( ); } + /** + * @param string[] $ignore_mixins + */ private static function handleRegularMixins( ClassLikeStorage $class_storage, TNamedObject $lhs_type_part, @@ -1269,9 +1272,13 @@ private static function handleRegularMixins( PhpParser\Node\Expr\PropertyFetch $stmt, StatementsAnalyzer $statements_analyzer, string $fq_class_name, + array $ignore_mixins = [], ) { $property_exists = false; $naive_property_exists = false; + + $ignore_mixins = [...$ignore_mixins, $fq_class_name]; + foreach ($class_storage->namedMixins as $mixin) { $new_property_id = $mixin->value . '::$' . $prop_name; @@ -1314,6 +1321,9 @@ private static function handleRegularMixins( } $mixin_lhs_type_part = $mixin; $mixin_fq_class_name = $mixin_class_storage->name; + if (in_array($mixin_fq_class_name, $ignore_mixins)) { + continue; + } [$new_lhs_type_part, $new_class_storage, $property_exists, $naive_property_exists, $new_property_id, $new_fq_class_name] = self::handleRegularMixins( $mixin_class_storage, @@ -1326,6 +1336,7 @@ private static function handleRegularMixins( $stmt, $statements_analyzer, $mixin_fq_class_name, + $ignore_mixins, ); if ($property_exists) { $fq_class_name = $new_fq_class_name; diff --git a/tests/MixinsDeepTest.php b/tests/MixinsDeepTest.php index 98c48ddb50b..55961d10171 100644 --- a/tests/MixinsDeepTest.php +++ b/tests/MixinsDeepTest.php @@ -442,6 +442,56 @@ public static function __callStatic(string $name, array $arguments) {} ], 'ignored_issues' => ['MixedAssignment'], ], + 'LowMixinCollision_WithProperties' => [ + 'code' => <<<'PHP' + notExistsProp; + PHP, + 'assertions' => [ + '$a' => 'mixed', + ], + 'ignored_issues' => ['MixedAssignment'], + ], + 'DeepMixinCollision_WithProperties' => [ + 'code' => <<<'PHP' + notExistsProp; + PHP, + 'assertions' => [ + '$a' => 'mixed', + ], + 'ignored_issues' => ['MixedAssignment'], + ], ]; } }