1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 12:55:26 +01:00

Merge pull request #6612 from orklah/empty-array_is_list

array_is_list on empty array returns true
This commit is contained in:
orklah 2021-10-08 17:16:35 +02:00 committed by GitHub
commit d40335ff37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -1897,6 +1897,13 @@ class SimpleAssertionReconciler extends \Psalm\Type\Reconciler
}
}
if ($type->type_params[0]->isEmpty()
|| $type->type_params[1]->isEmpty()
) {
//we allow an empty array to pass as a list. We keep the type as empty array though (more precise)
$array_types[] = $type;
}
$did_remove_type = true;
} elseif ($type instanceof TCallable) {
$array_types[] = new TCallableKeyedArray([

View File

@ -1632,6 +1632,18 @@ class FunctionCallTest extends TestCase
[],
'8.1',
],
'array_is_list_on_empty_array' => [
'<?php
$a = [];
if(array_is_list($a)) {
//$a is still empty array
}
',
[],
[],
'8.1',
],
];
}