mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix #1287 - improve handling of templated intersection
This commit is contained in:
parent
020430c66f
commit
d45326759f
@ -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';
|
||||
|
@ -1559,6 +1559,28 @@ class TemplateTest extends TestCase
|
||||
return new C(new $t);
|
||||
}',
|
||||
],
|
||||
'templateIntersectionLeft' => [
|
||||
'<?php
|
||||
interface I1 {}
|
||||
interface I2 {}
|
||||
|
||||
/**
|
||||
* @template T as I1&I2
|
||||
* @param T $a
|
||||
*/
|
||||
function templatedBar(I1 $a) : void {}'
|
||||
],
|
||||
'templateIntersectionRight' => [
|
||||
'<?php
|
||||
interface I1 {}
|
||||
interface I2 {}
|
||||
|
||||
/**
|
||||
* @template T as I1&I2
|
||||
* @param T $b
|
||||
*/
|
||||
function templatedBar(I2 $b) : void {}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user