mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
parent
5c511ad95d
commit
3e07684855
@ -684,6 +684,23 @@ class TypeAnalyzer
|
||||
continue 2;
|
||||
}
|
||||
|
||||
if ($intersection_container_type_lower === 'iterable') {
|
||||
if ($intersection_input_type_lower === 'traversable'
|
||||
|| ($codebase->classlikes->classExists($intersection_input_type_lower)
|
||||
&& $codebase->classlikes->classImplements(
|
||||
$intersection_input_type_lower,
|
||||
'Traversable'
|
||||
))
|
||||
|| ($codebase->classlikes->interfaceExists($intersection_input_type_lower)
|
||||
&& $codebase->classlikes->interfaceExtends(
|
||||
$intersection_input_type_lower,
|
||||
'Traversable'
|
||||
))
|
||||
) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
if ($intersection_input_type_lower === 'traversable'
|
||||
&& $intersection_container_type_lower === 'iterable'
|
||||
) {
|
||||
|
@ -3171,6 +3171,21 @@ class ClassTemplateTest extends TestCase
|
||||
}',
|
||||
'error_message' => 'InvalidArgument'
|
||||
],
|
||||
'preventIteratorAggregateToIterableWithDifferentTypes' => [
|
||||
'<?php
|
||||
class Foo {}
|
||||
|
||||
class Bar {}
|
||||
|
||||
/** @param iterable<int, Foo> $foos */
|
||||
function consume(iterable $foos): void {}
|
||||
|
||||
/** @param IteratorAggregate<int, Bar> $t */
|
||||
function foo(IteratorAggregate $t) : void {
|
||||
consume($t);
|
||||
}',
|
||||
'error_message' => 'InvalidArgument',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user