Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Sep 1, 2024
1 parent e30b958 commit 4612d46
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Type/Constant/ConstantArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,9 @@ public function unsetOffset(Type $offsetType): Type
$k++;
}

return new self($newKeyTypes, $newValueTypes, $this->nextAutoIndexes, $newOptionalKeys, TrinaryLogic::createNo());
$isList = $this->isList()->and(TrinaryLogic::createFromBoolean($i === count($this->keyTypes) - 1));

return new self($newKeyTypes, $newValueTypes, $this->nextAutoIndexes, $newOptionalKeys, $isList);
}

return $this;
Expand Down
3 changes: 3 additions & 0 deletions src/Type/Constant/ConstantArrayTypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $opt
}

$max = max($this->nextAutoIndexes);
if ($max !== count($this->keyTypes)) {
$this->isList = TrinaryLogic::createNo();
}

$this->keyTypes[] = new ConstantIntegerType($max);
$this->valueTypes[] = $valueType;
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/nsrt/array-is-list-unset.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function () {
assertType('true', array_is_list($a));
unset($a[2]);
assertType('array{1, 2}', $a);
assertType('false', array_is_list($a));
assertType('true', array_is_list($a));
$a[] = 4;
assertType('array{0: 1, 1: 2, 3: 4}', $a);
assertType('false', array_is_list($a));
Expand Down

0 comments on commit 4612d46

Please sign in to comment.