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

Fix #1536 - prevent fatal error when filtering null array

This commit is contained in:
Brown 2019-04-09 17:22:30 -04:00
parent 5173c18cce
commit 1a33b25264
2 changed files with 18 additions and 0 deletions

View File

@ -130,6 +130,10 @@ class ArrayFilterReturnTypeProvider implements \Psalm\Plugin\Hook\FunctionReturn
]);
}
if (!$inner_type->getTypes()) {
return Type::getEmptyArray();
}
return new Type\Union([
new Type\Atomic\TArray([
$key_type,

View File

@ -81,6 +81,20 @@ class FunctionCallTest extends TestCase
'<?php
$foo = array_filter(["hello ", " "], "trim");',
],
'arrayFilterAllowNull' => [
'<?php
function foo() : array {
return array_filter(
array_map(
/** @return null */
function (int $arg) {
return null;
},
[1, 2, 3]
)
);
}',
],
'typedArrayWithDefault' => [
'<?php
class A {}