From 786ac6c4eb8154bc656bf47541799debdfb5cc01 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Thu, 22 Nov 2018 01:03:32 -0500 Subject: [PATCH] Allow static to carry intersection types --- .../Expression/Call/MethodCallAnalyzer.php | 2 +- .../Analyzer/Statements/ExpressionAnalyzer.php | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php index 49c4f6396..7b5188d08 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php @@ -673,7 +673,7 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\ $codebase, $return_type_candidate, $self_fq_class_name, - $fq_class_name + $fq_class_name . ($intersection_types ? '&' . implode('&', $intersection_types) : '') ); $return_type_location = $codebase->methods->getMethodReturnTypeLocation( diff --git a/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php index 8ff1aba9c..2f8b5a84e 100644 --- a/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php @@ -889,7 +889,18 @@ class ExpressionAnalyzer ); } - $return_type->value = $static_class; + if (strpos($static_class, '&')) { + $static_classes = explode('&', $static_class); + $return_type->value = array_shift($static_classes); + $return_type->extra_types = array_map( + function (string $extra_type) : Type\Atomic\TNamedObject { + return new Type\Atomic\TNamedObject($extra_type); + }, + $static_classes + ); + } else { + $return_type->value = $static_class; + } } elseif ($return_type_lc === 'self') { if (!$self_class) { throw new \UnexpectedValueException(