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:
parent
5173c18cce
commit
1a33b25264
@ -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,
|
||||
|
@ -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 {}
|
||||
|
Loading…
Reference in New Issue
Block a user