Skip to content

Commit 3c026f6

Browse files
committed
fixup! Ignore negative keys on checking whether a ConstantArray is a list
1 parent e20a0cc commit 3c026f6

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/Type/Constant/ConstantArrayTypeBuilder.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,19 +162,25 @@ public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $opt
162162
$this->keyTypes[] = $offsetType;
163163
$this->valueTypes[] = $valueType;
164164

165-
if ($offsetType instanceof ConstantIntegerType && $offsetType->getValue() >= 0) {
165+
if ($offsetType instanceof ConstantIntegerType) {
166166
$min = min($this->nextAutoIndexes);
167167
$max = max($this->nextAutoIndexes);
168-
if ($offsetType->getValue() > $min) {
169-
if ($offsetType->getValue() <= $max) {
170-
$this->isList = $this->isList->and(TrinaryLogic::createMaybe());
171-
} else {
172-
$this->isList = TrinaryLogic::createNo();
168+
$offsetValue = $offsetType->getValue();
169+
if ($offsetValue >= 0) {
170+
if ($offsetValue > $min) {
171+
if ($offsetValue <= $max) {
172+
$this->isList = $this->isList->and(TrinaryLogic::createMaybe());
173+
} else {
174+
$this->isList = TrinaryLogic::createNo();
175+
}
173176
}
177+
} else {
178+
$this->isList = TrinaryLogic::createNo();
174179
}
175-
if ($offsetType->getValue() >= $max) {
180+
181+
if ($offsetValue >= $max) {
176182
/** @var int|float $newAutoIndex */
177-
$newAutoIndex = $offsetType->getValue() + 1;
183+
$newAutoIndex = $offsetValue + 1;
178184
if (is_float($newAutoIndex)) {
179185
$newAutoIndex = $max;
180186
}

0 commit comments

Comments
 (0)