Skip to content

Commit 5e5ab7a

Browse files
committed
Revert "Cleanup instanceof Type checks"
This partially reverts commit 3b72271.
1 parent 9aeb490 commit 5e5ab7a

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/Analyser/MutatingScope.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4341,29 +4341,24 @@ public function specifyExpressionType(Expr $expr, Type $type, Type $nativeType,
43414341
&& !$expr->dim instanceof Expr\PostInc
43424342
) {
43434343
$dimType = $scope->getType($expr->dim)->toArrayKey();
4344-
if ($dimType->isInteger()->yes() || $dimType->isString()->yes()) {
4344+
if ($dimType instanceof ConstantIntegerType || $dimType instanceof ConstantStringType) {
43454345
$exprVarType = $scope->getType($expr->var);
43464346
if (!$exprVarType instanceof MixedType && !$exprVarType->isArray()->no()) {
43474347
$types = [
43484348
new ArrayType(new MixedType(), new MixedType()),
43494349
new ObjectType(ArrayAccess::class),
43504350
new NullType(),
43514351
];
4352-
if ($dimType->isInteger()->yes()) {
4352+
if ($dimType instanceof ConstantIntegerType) {
43534353
$types[] = new StringType();
43544354
}
4355-
$offsetValueType = TypeCombinator::intersect($exprVarType, TypeCombinator::union(...$types));
4356-
4357-
if ($dimType instanceof ConstantIntegerType || $dimType instanceof ConstantStringType) {
4358-
$offsetValueType = TypeCombinator::intersect(
4359-
$offsetValueType,
4360-
new HasOffsetValueType($dimType, $type),
4361-
);
4362-
}
43634355

43644356
$scope = $scope->specifyExpressionType(
43654357
$expr->var,
4366-
$offsetValueType,
4358+
TypeCombinator::intersect(
4359+
TypeCombinator::intersect($exprVarType, TypeCombinator::union(...$types)),
4360+
new HasOffsetValueType($dimType, $type),
4361+
),
43674362
$scope->getNativeType($expr->var),
43684363
$certainty,
43694364
);

0 commit comments

Comments
 (0)