Skip to content

Commit 457de4e

Browse files
committed
Revert "Cleanup instanceof Type checks"
This partially reverts commit 3b72271.
1 parent 1dd6b3f commit 457de4e

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
@@ -4367,29 +4367,24 @@ public function specifyExpressionType(Expr $expr, Type $type, Type $nativeType,
43674367
&& !$expr->dim instanceof Expr\PostInc
43684368
) {
43694369
$dimType = $scope->getType($expr->dim)->toArrayKey();
4370-
if ($dimType->isInteger()->yes() || $dimType->isString()->yes()) {
4370+
if ($dimType instanceof ConstantIntegerType || $dimType instanceof ConstantStringType) {
43714371
$exprVarType = $scope->getType($expr->var);
43724372
if (!$exprVarType instanceof MixedType && !$exprVarType->isArray()->no()) {
43734373
$types = [
43744374
new ArrayType(new MixedType(), new MixedType()),
43754375
new ObjectType(ArrayAccess::class),
43764376
new NullType(),
43774377
];
4378-
if ($dimType->isInteger()->yes()) {
4378+
if ($dimType instanceof ConstantIntegerType) {
43794379
$types[] = new StringType();
43804380
}
4381-
$offsetValueType = TypeCombinator::intersect($exprVarType, TypeCombinator::union(...$types));
4382-
4383-
if ($dimType instanceof ConstantIntegerType || $dimType instanceof ConstantStringType) {
4384-
$offsetValueType = TypeCombinator::intersect(
4385-
$offsetValueType,
4386-
new HasOffsetValueType($dimType, $type),
4387-
);
4388-
}
43894381

43904382
$scope = $scope->specifyExpressionType(
43914383
$expr->var,
4392-
$offsetValueType,
4384+
TypeCombinator::intersect(
4385+
TypeCombinator::intersect($exprVarType, TypeCombinator::union(...$types)),
4386+
new HasOffsetValueType($dimType, $type),
4387+
),
43934388
$scope->getNativeType($expr->var),
43944389
$certainty,
43954390
);

0 commit comments

Comments
 (0)