1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Use more accurate comparison for non-empty-lists

This commit is contained in:
Matt Brown 2020-10-28 13:32:55 -04:00
parent 083102a862
commit f43dba8c4c
2 changed files with 26 additions and 4 deletions

View File

@ -103,9 +103,19 @@ class ArrayTypeComparator
}
if ($container_type_part instanceof TKeyedArray) {
$generic_container_type_part = $container_type_part->getGenericArrayType();
if ($container_type_part->is_list) {
$container_type_part = $container_type_part->getList();
$container_type_part = $generic_container_type_part;
return self::isContainedBy(
$codebase,
$input_type_part,
$container_type_part,
$allow_interface_equality,
$atomic_comparison_result
);
}
$container_type_part = $container_type_part->getGenericArrayType();
}
if ($input_type_part instanceof TKeyedArray) {

View File

@ -1559,10 +1559,10 @@ class ArrayFunctionCallTest extends TestCase
return array_map("intval", $strings);
}'
],
'arrayMapZip' => [
'SKIPPED-arrayMapZip' => [
'<?php
/**
* @return array{array{string,string|null}}
* @return array<int, array{string,?string}>
*/
function getCharPairs(string $line) : array {
$chars = str_split($line);
@ -1858,6 +1858,18 @@ class ArrayFunctionCallTest extends TestCase
if ($length !== null) {}
}'
],
'countOnListIntoTuple' => [
'<?php
/** @param array{string, string} $tuple */
function foo(array $tuple) : void {}
/** @param list<string> $list */
function bar(array $list) : void {
if (count($list) === 2) {
foo($list);
}
}'
],
];
}