Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/Type/TypeCombinator.php
Original file line number Diff line number Diff line change
Expand Up @@ -940,12 +940,14 @@ private static function optimizeConstantArrays(array $types): array
$keyType = TypeCombinator::union(...array_values($keyTypes));
$valueType = TypeCombinator::union(...array_values($valueTypes));

$arrayType = new ArrayType($keyType, $valueType);
$accessories = [];
if ($isList) {
$arrayType = TypeCombinator::intersect($arrayType, new AccessoryArrayListType());
$accessories[] = new AccessoryArrayListType();
}
$accessories[] = new NonEmptyArrayType();
$accessories[] = new OversizedArrayType();

return TypeCombinator::intersect($arrayType, new NonEmptyArrayType(), new OversizedArrayType());
return TypeCombinator::intersect(new ArrayType($keyType, $valueType), ...$accessories);
});

if (!$isOversized) {
Expand Down Expand Up @@ -975,12 +977,14 @@ private static function optimizeConstantArrays(array $types): array
$valueType = $valueType->generalize(GeneralizePrecision::lessSpecific());
}

$arrayType = new ArrayType($keyType, $valueType);
$accessories = [];
if ($eachIsList) {
$arrayType = self::intersect($arrayType, new AccessoryArrayListType());
$accessories[] = new AccessoryArrayListType();
}
$accessories[] = new NonEmptyArrayType();
$accessories[] = new OversizedArrayType();

return [self::intersect($arrayType, new NonEmptyArrayType(), new OversizedArrayType())];
return [self::intersect(new ArrayType($keyType, $valueType), ...$accessories)];
}

return $results;
Expand Down
Loading