diff --git a/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php index 15d565dd7..6d95fa650 100644 --- a/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php @@ -1306,16 +1306,20 @@ class ExpressionAnalyzer } elseif ($return_type->was_static && ($static_class_type instanceof Type\Atomic\TNamedObject || $static_class_type instanceof Type\Atomic\TTemplateParam) - && $static_class_type->getKey(false) !== $return_type->getKey(false) ) { $return_type = clone $return_type; $cloned_static = clone $static_class_type; $extra_static = $cloned_static->extra_types ?: []; $cloned_static->extra_types = null; - $return_type->extra_types[$static_class_type->getKey()] = clone $cloned_static; + + if ($cloned_static->getKey(false) !== $return_type->getKey(false)) { + $return_type->extra_types[$static_class_type->getKey()] = clone $cloned_static; + } foreach ($extra_static as $extra_static_type) { - $return_type->extra_types[$extra_static_type->getKey()] = clone $extra_static_type; + if ($extra_static_type->getKey(false) !== $return_type->getKey(false)) { + $return_type->extra_types[$extra_static_type->getKey()] = clone $extra_static_type; + } } } elseif ($return_type_lc === 'self') { if (!$self_class) {