From 78e183ea0c470b2e14980dd6f6a691770628ee20 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Wed, 26 Oct 2016 17:51:34 -0400 Subject: [PATCH] Filter null & false if no arg passed to array_filter --- src/Psalm/Checker/FunctionChecker.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Psalm/Checker/FunctionChecker.php b/src/Psalm/Checker/FunctionChecker.php index 3018192e1..e78f6a126 100644 --- a/src/Psalm/Checker/FunctionChecker.php +++ b/src/Psalm/Checker/FunctionChecker.php @@ -373,6 +373,14 @@ class FunctionChecker extends FunctionLikeChecker // where there's no function passed to array_filter if ($call_map_key === 'array_filter' && $first_arg && isset($first_arg->inferredType) && $first_arg->inferredType->hasArray()) { $inner_type = clone $first_arg->inferredType->types['array']->type_params[1]; + + $second_arg = isset($call_args[1]->value) ? $call_args[1]->value : null; + + if (!$second_arg) { + $inner_type->removeType('null'); + $inner_type->removeType('false'); + } + return new Type\Union([new Type\Generic('array', [Type::getInt(), $inner_type])]); }