Skip to content

Commit

Permalink
skip UnionType offset because it's hard to solve in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
rajyan committed May 12, 2022
1 parent c0bf915 commit bd2eb4e
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -4174,26 +4174,18 @@ public function specifyExpressionType(Expr $expr, Type $type, ?Type $nativeType
if (count($constantArrays) > 0) {
$setArrays = [];
$dimType = $this->getType($expr->dim);
if ($dimType instanceof UnionType) {
$dimTypes = $dimType->getTypes();
} else {
$dimTypes = [$dimType];
}
foreach ($constantArrays as $constantArray) {
foreach ($dimTypes as $innerType) {
if ($constantArray->hasOffsetValueType($innerType)->no()) {
continue;
}
if (!$dimType instanceof UnionType) {
foreach ($constantArrays as $constantArray) {
$setArrays[] = $constantArray->setOffsetValueType(
TypeCombinator::intersect(ArrayType::castToArrayKeyType($innerType), $constantArray->getKeyType()),
$dimType instanceof UnionType ? TypeCombinator::intersect($type, $constantArray->getOffsetValueType($innerType)) : $type,
TypeCombinator::intersect(ArrayType::castToArrayKeyType($dimType), $constantArray->getKeyType()),
$type
);
}
$scope = $this->specifyExpressionType(
$expr->var,
TypeCombinator::union(...$setArrays),
);
}
$scope = $this->specifyExpressionType(
$expr->var,
TypeCombinator::union(...$setArrays),
);
}
}

Expand Down

0 comments on commit bd2eb4e

Please sign in to comment.