Skip to content

Commit 96b6caf

Browse files
committed
fix
1 parent adedb12 commit 96b6caf

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/Type/IntersectionType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ public function getArraySize(): Type
691691
$knownOffsets[$type->getOffsetType()->getValue()] = true;
692692
}
693693

694-
if ($this->isIterableAtLeastOnce()->yes()) {
694+
if ($this->isList()->yes() && $this->isIterableAtLeastOnce()->yes()) {
695695
$knownOffsets[0] = true;
696696
}
697697

@@ -844,7 +844,7 @@ public function hasOffsetValueType(Type $offsetType): TrinaryLogic
844844

845845
$size = $this->getArraySize();
846846
if ($size instanceof IntegerRangeType && $size->getMin() !== null) {
847-
$knownOffsets = IntegerRangeType::fromInterval(0, $size->getMin());
847+
$knownOffsets = IntegerRangeType::fromInterval(0, $size->getMin() - 1);
848848
} elseif ($size instanceof ConstantIntegerType) {
849849
$knownOffsets = IntegerRangeType::fromInterval(0, $size->getValue());
850850
} elseif ($this->isIterableAtLeastOnce()->yes()) {

tests/PHPStan/Analyser/nsrt/count-recursive.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,18 @@ public function countList($list): void
8484
{
8585
if (count($list) > 2) {
8686
assertType('int<3, max>', count($list));
87-
assertType('int<2, max>', count($list, COUNT_NORMAL));
88-
assertType('int<2, max>', count($list, COUNT_RECURSIVE));
87+
assertType('int<3, max>', count($list, COUNT_NORMAL));
88+
assertType('int<3, max>', count($list, COUNT_RECURSIVE));
8989
}
9090
}
9191

9292
/** @param list<int> $list */
9393
public function countListNormal($list): void
9494
{
9595
if (count($list, COUNT_NORMAL) > 2) {
96-
assertType('int<2, max>', count($list));
96+
assertType('int<3, max>', count($list));
9797
assertType('int<3, max>', count($list, COUNT_NORMAL));
98-
assertType('int<2, max>', count($list, COUNT_RECURSIVE));
98+
assertType('int<3, max>', count($list, COUNT_RECURSIVE));
9999
}
100100
}
101101

@@ -124,8 +124,8 @@ public function countMixed($arr, $mode): void
124124
public function countListRecursive($list): void
125125
{
126126
if (count($list, COUNT_RECURSIVE) > 2) {
127-
assertType('int<2, max>', count($list));
128-
assertType('int<2, max>', count($list, COUNT_NORMAL));
127+
assertType('int<3, max>', count($list));
128+
assertType('int<3, max>', count($list, COUNT_NORMAL));
129129
assertType('int<3, max>', count($list, COUNT_RECURSIVE));
130130
}
131131
}

0 commit comments

Comments
 (0)