From d45326759fd3a713d7ddb815145f6164a20e437b Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Wed, 6 Feb 2019 12:37:05 -0500 Subject: [PATCH] Fix #1287 - improve handling of templated intersection --- src/Psalm/Internal/Analyzer/TypeAnalyzer.php | 22 ++++++++++++++++++++ tests/Template/TemplateTest.php | 22 ++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/Psalm/Internal/Analyzer/TypeAnalyzer.php b/src/Psalm/Internal/Analyzer/TypeAnalyzer.php index c8afd39b6..415252194 100644 --- a/src/Psalm/Internal/Analyzer/TypeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/TypeAnalyzer.php @@ -307,9 +307,31 @@ class TypeAnalyzer $intersection_input_types = $input_type_part->extra_types ?: []; $intersection_input_types[] = $input_type_part; + if ($input_type_part instanceof TGenericParam) { + foreach ($input_type_part->as->getTypes() as $g) { + if ($g instanceof TNamedObject && $g->extra_types) { + $intersection_input_types = array_merge( + $intersection_input_types, + $g->extra_types + ); + } + } + } + $intersection_container_types = $container_type_part->extra_types ?: []; $intersection_container_types[] = $container_type_part; + if ($container_type_part instanceof TGenericParam) { + foreach ($container_type_part->as->getTypes() as $g) { + if ($g instanceof TNamedObject && $g->extra_types) { + $intersection_container_types = array_merge( + $intersection_container_types, + $g->extra_types + ); + } + } + } + foreach ($intersection_container_types as $intersection_container_type) { if ($intersection_container_type instanceof TIterable) { $intersection_container_type_lower = 'iterable'; diff --git a/tests/Template/TemplateTest.php b/tests/Template/TemplateTest.php index 9ab88612c..47088c256 100644 --- a/tests/Template/TemplateTest.php +++ b/tests/Template/TemplateTest.php @@ -1559,6 +1559,28 @@ class TemplateTest extends TestCase return new C(new $t); }', ], + 'templateIntersectionLeft' => [ + ' [ + '