Skip to content

Commit

Permalink
use BenevolentUnionType
Browse files Browse the repository at this point in the history
  • Loading branch information
mglaman authored and ondrejmirtes committed Nov 28, 2023
1 parent 0044649 commit 093bbb2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
use PHPStan\Type\ErrorType;
use PHPStan\Type\MixedType;
use PHPStan\Type\NeverType;
use PHPStan\Type\NullType;
use PHPStan\Type\StaticTypeFactory;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypeUtils;
use function array_map;
use function count;
use function is_string;
Expand All @@ -55,13 +55,10 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
}

$arrayArgType = $scope->getType($arrayArg);
$arrayArgType->isArray();
$arrayArgType = TypeUtils::toBenevolentUnion($arrayArgType);
$keyType = $arrayArgType->getIterableKeyType();
$itemType = $arrayArgType->getIterableValueType();

if ($itemType instanceof ErrorType || $keyType instanceof ErrorType) {
return new ConstantArrayType([], []);
}
if ($itemType instanceof NeverType || $keyType instanceof NeverType) {
return new ConstantArrayType([], []);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/data/bug-10189.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function file_managed_file_save_upload(): array {
}
assertType('non-empty-array|Bug10189\SomeInterface', $files);
$files = array_filter($files);
assertType('array{}', $files);
assertType("array<mixed~0|0.0|''|'0'|array{}|false|null>", $files);

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

0 comments on commit 093bbb2

Please sign in to comment.