Skip to content

Commit

Permalink
Revert "ConstantArrayTypeBuilder - generalize key types and value typ…
Browse files Browse the repository at this point in the history
…es in degraded general array"

This reverts commit dbdcb81.
  • Loading branch information
ondrejmirtes committed Sep 6, 2022
1 parent 8a3562e commit 8250448
Show file tree
Hide file tree
Showing 3 changed files with 626 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/Type/Constant/ConstantArrayTypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use PHPStan\ShouldNotHappenException;
use PHPStan\Type\Accessory\NonEmptyArrayType;
use PHPStan\Type\ArrayType;
use PHPStan\Type\GeneralizePrecision;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypeUtils;
Expand Down Expand Up @@ -267,16 +266,10 @@ public function getArray(): Type
return new ConstantArrayType($keyTypes, $this->valueTypes, $this->nextAutoIndexes, $this->optionalKeys);
}

$keyType = TypeCombinator::union(...$this->keyTypes);
if (count(TypeUtils::getConstantScalars($keyType)) > self::ARRAY_COUNT_LIMIT) {
$keyType = $keyType->generalize(GeneralizePrecision::moreSpecific());
}
$valueType = TypeCombinator::union(...$this->valueTypes);
if (count(TypeUtils::getConstantScalars($valueType)) > self::ARRAY_COUNT_LIMIT) {
$valueType = $valueType->generalize(GeneralizePrecision::moreSpecific());
}

$array = new ArrayType($keyType, $valueType);
$array = new ArrayType(
TypeCombinator::union(...$this->keyTypes),
TypeCombinator::union(...$this->valueTypes),
);

if (count($this->optionalKeys) < $keyTypesCount) {
return TypeCombinator::intersect($array, new NonEmptyArrayType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,9 @@ public function testBug5607(): void
]);
}

public function testBug7933(): void
{
$this->analyse([__DIR__ . '/data/bug-7933.php'], []);
}

}
Loading

0 comments on commit 8250448

Please sign in to comment.