Skip to content

Commit 97685b2

Browse files
Fix
1 parent bb95c5a commit 97685b2

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

Diff for: src/Type/Constant/ConstantArrayType.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,9 @@ public function unsetOffset(Type $offsetType): Type
734734
$k++;
735735
}
736736

737-
return new self($newKeyTypes, $newValueTypes, $this->nextAutoIndexes, $newOptionalKeys, TrinaryLogic::createNo());
737+
$isList = $this->isList()->and(TrinaryLogic::createFromBoolean($i === count($this->keyTypes) - 1));
738+
739+
return new self($newKeyTypes, $newValueTypes, $this->nextAutoIndexes, $newOptionalKeys, $isList);
738740
}
739741

740742
return $this;

Diff for: src/Type/Constant/ConstantArrayTypeBuilder.php

+3
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $opt
109109
}
110110

111111
$max = max($this->nextAutoIndexes);
112+
if ($max !== count($this->keyTypes)) {
113+
$this->isList = TrinaryLogic::createNo();
114+
}
112115

113116
$this->keyTypes[] = new ConstantIntegerType($max);
114117
$this->valueTypes[] = $valueType;

Diff for: tests/PHPStan/Analyser/nsrt/array-is-list-unset.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function () {
1919
assertType('true', array_is_list($a));
2020
unset($a[2]);
2121
assertType('array{1, 2}', $a);
22-
assertType('false', array_is_list($a));
22+
assertType('true', array_is_list($a));
2323
$a[] = 4;
2424
assertType('array{0: 1, 1: 2, 3: 4}', $a);
2525
assertType('false', array_is_list($a));

0 commit comments

Comments
 (0)