Skip to content

Commit

Permalink
ConstantArrayType::generalize() - empty array will remain ConstantArr…
Browse files Browse the repository at this point in the history
…ayType
  • Loading branch information
ondrejmirtes committed Dec 10, 2019
1 parent 3dadf2a commit 3e4d7b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Reflection/Php/PhpClassReflectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
use PHPStan\Reflection\SignatureMap\ParameterSignature;
use PHPStan\Reflection\SignatureMap\SignatureMapProvider;
use PHPStan\TrinaryLogic;
use PHPStan\Type\ArrayType;
use PHPStan\Type\Constant\ConstantArrayType;
use PHPStan\Type\ErrorType;
use PHPStan\Type\FileTypeMapper;
use PHPStan\Type\Generic\TemplateTypeHelper;
Expand Down Expand Up @@ -765,7 +767,12 @@ private function inferAndCachePropertyTypes(
continue;
}

$propertyTypes[$propertyFetch->name->toString()] = TypeUtils::generalizeType($propertyType);
$propertyType = TypeUtils::generalizeType($propertyType);
if ($propertyType instanceof ConstantArrayType) {
$propertyType = new ArrayType(new MixedType(true), new MixedType(true));
}

$propertyTypes[$propertyFetch->name->toString()] = $propertyType;
}

return $this->propertyTypesCache[$declaringClass->getName()] = $propertyTypes;
Expand Down
4 changes: 4 additions & 0 deletions src/Type/Constant/ConstantArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@ public function toBoolean(): BooleanType

public function generalize(): Type
{
if (count($this->keyTypes) === 0) {
return $this;
}

return new ArrayType(
TypeUtils::generalizeType($this->getKeyType()),
$this->getItemType()
Expand Down

0 comments on commit 3e4d7b3

Please sign in to comment.