From bd2eb4e6839a694c7f13c2e5d856efbccc63828c Mon Sep 17 00:00:00 2001 From: Yohta Kimura Date: Fri, 13 May 2022 01:55:32 +0900 Subject: [PATCH] skip UnionType offset because it's hard to solve in some cases --- src/Analyser/MutatingScope.php | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index 1e0a3548ba3..d284cbff21e 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -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), - ); } }