Skip to content

Commit 093bbb2

Browse files
mglamanondrejmirtes
authored andcommitted
use BenevolentUnionType
1 parent 0044649 commit 093bbb2

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

src/Type/Php/ArrayFilterFunctionReturnTypeReturnTypeExtension.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
2424
use PHPStan\Type\Constant\ConstantBooleanType;
2525
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
26-
use PHPStan\Type\ErrorType;
2726
use PHPStan\Type\MixedType;
2827
use PHPStan\Type\NeverType;
2928
use PHPStan\Type\NullType;
3029
use PHPStan\Type\StaticTypeFactory;
3130
use PHPStan\Type\Type;
3231
use PHPStan\Type\TypeCombinator;
32+
use PHPStan\Type\TypeUtils;
3333
use function array_map;
3434
use function count;
3535
use function is_string;
@@ -55,13 +55,10 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
5555
}
5656

5757
$arrayArgType = $scope->getType($arrayArg);
58-
$arrayArgType->isArray();
58+
$arrayArgType = TypeUtils::toBenevolentUnion($arrayArgType);
5959
$keyType = $arrayArgType->getIterableKeyType();
6060
$itemType = $arrayArgType->getIterableValueType();
6161

62-
if ($itemType instanceof ErrorType || $keyType instanceof ErrorType) {
63-
return new ConstantArrayType([], []);
64-
}
6562
if ($itemType instanceof NeverType || $keyType instanceof NeverType) {
6663
return new ConstantArrayType([], []);
6764
}

tests/PHPStan/Analyser/data/bug-10189.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function file_managed_file_save_upload(): array {
2020
}
2121
assertType('non-empty-array|Bug10189\SomeInterface', $files);
2222
$files = array_filter($files);
23-
assertType('array{}', $files);
23+
assertType("array<mixed~0|0.0|''|'0'|array{}|false|null>", $files);
2424

2525
return empty($files) ? [] : [1,2];
2626
}

0 commit comments

Comments
 (0)