Skip to content

Commit 073da14

Browse files
committed
Remove instanceof Type checks
1 parent 79326d6 commit 073da14

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/Analyser/MutatingScope.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4310,24 +4310,29 @@ public function specifyExpressionType(Expr $expr, Type $type, Type $nativeType,
43104310
$scope = $this;
43114311
if ($expr instanceof Expr\ArrayDimFetch && $expr->dim !== null) {
43124312
$dimType = $scope->getType($expr->dim)->toArrayKey();
4313-
if ($dimType instanceof ConstantIntegerType || $dimType instanceof ConstantStringType) {
4313+
if ($dimType->isInteger()->yes() || $dimType->isString()->yes()) {
43144314
$exprVarType = $scope->getType($expr->var);
43154315
if (!$exprVarType instanceof MixedType && !$exprVarType->isArray()->no()) {
43164316
$types = [
43174317
new ArrayType(new MixedType(), new MixedType()),
43184318
new ObjectType(ArrayAccess::class),
43194319
new NullType(),
43204320
];
4321-
if ($dimType instanceof ConstantIntegerType) {
4321+
if ($dimType->isInteger()->yes()) {
43224322
$types[] = new StringType();
43234323
}
4324+
$offsetValueType = TypeCombinator::intersect($exprVarType, TypeCombinator::union(...$types));
4325+
4326+
if ($dimType instanceof ConstantIntegerType || $dimType instanceof ConstantStringType) {
4327+
$offsetValueType = TypeCombinator::intersect(
4328+
$offsetValueType,
4329+
new HasOffsetValueType($dimType, $type),
4330+
);
4331+
}
43244332

43254333
$scope = $scope->specifyExpressionType(
43264334
$expr->var,
4327-
TypeCombinator::intersect(
4328-
TypeCombinator::intersect($exprVarType, TypeCombinator::union(...$types)),
4329-
new HasOffsetValueType($dimType, $type),
4330-
),
4335+
$offsetValueType,
43314336
$scope->getNativeType($expr->var),
43324337
$certainty,
43334338
);

0 commit comments

Comments
 (0)