Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/Type/Constant/ConstantArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -859,8 +859,6 @@ public function unsetOffset(Type $offsetType, bool $preserveListCertainty = fals
);
if (!$preserveListCertainty) {
$newIsList = $newIsList->and(TrinaryLogic::createMaybe());
} elseif ($this->isList->yes() && $newIsList->no()) {
return new NeverType();
}

return $this->recreate($this->keyTypes, $this->valueTypes, $this->nextAutoIndexes, $optionalKeys, $newIsList);
Expand Down Expand Up @@ -1744,12 +1742,16 @@ public function tryRemove(Type $typeToRemove): ?Type
return new ConstantArrayType([], []);
}

if ($typeToRemove instanceof HasOffsetType) {
return $this->unsetOffset($typeToRemove->getOffsetType(), true);
}

if ($typeToRemove instanceof HasOffsetValueType) {
return $this->unsetOffset($typeToRemove->getOffsetType(), true);
if ($typeToRemove instanceof HasOffsetType || $typeToRemove instanceof HasOffsetValueType) {
$unsetResult = $this->unsetOffset($typeToRemove->getOffsetType(), true);
// When the source was definitely a list but the post-unset shape
// definitely isn't (e.g. unsetting a non-optional leading key
// creates a hole), no value of $this could have lacked the
// removed key — the subtraction yields the empty set.
if ($this->isList->yes() && $unsetResult->isList()->no()) {
return new NeverType();
}
return $unsetResult;
}

return null;
Expand Down
Loading