Skip to content

Commit 8250448

Browse files
committed
Revert "ConstantArrayTypeBuilder - generalize key types and value types in degraded general array"
This reverts commit dbdcb81.
1 parent 8a3562e commit 8250448

File tree

3 files changed

+626
-11
lines changed

3 files changed

+626
-11
lines changed

src/Type/Constant/ConstantArrayTypeBuilder.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use PHPStan\ShouldNotHappenException;
66
use PHPStan\Type\Accessory\NonEmptyArrayType;
77
use PHPStan\Type\ArrayType;
8-
use PHPStan\Type\GeneralizePrecision;
98
use PHPStan\Type\Type;
109
use PHPStan\Type\TypeCombinator;
1110
use PHPStan\Type\TypeUtils;
@@ -267,16 +266,10 @@ public function getArray(): Type
267266
return new ConstantArrayType($keyTypes, $this->valueTypes, $this->nextAutoIndexes, $this->optionalKeys);
268267
}
269268

270-
$keyType = TypeCombinator::union(...$this->keyTypes);
271-
if (count(TypeUtils::getConstantScalars($keyType)) > self::ARRAY_COUNT_LIMIT) {
272-
$keyType = $keyType->generalize(GeneralizePrecision::moreSpecific());
273-
}
274-
$valueType = TypeCombinator::union(...$this->valueTypes);
275-
if (count(TypeUtils::getConstantScalars($valueType)) > self::ARRAY_COUNT_LIMIT) {
276-
$valueType = $valueType->generalize(GeneralizePrecision::moreSpecific());
277-
}
278-
279-
$array = new ArrayType($keyType, $valueType);
269+
$array = new ArrayType(
270+
TypeCombinator::union(...$this->keyTypes),
271+
TypeCombinator::union(...$this->valueTypes),
272+
);
280273

281274
if (count($this->optionalKeys) < $keyTypesCount) {
282275
return TypeCombinator::intersect($array, new NonEmptyArrayType());

tests/PHPStan/Rules/Properties/DefaultValueTypesAssignedToPropertiesRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,9 @@ public function testBug5607(): void
5555
]);
5656
}
5757

58+
public function testBug7933(): void
59+
{
60+
$this->analyse([__DIR__ . '/data/bug-7933.php'], []);
61+
}
62+
5863
}

0 commit comments

Comments
 (0)