Skip to content

Commit 50df3b6

Browse files
committed
added inverse test
1 parent c93be94 commit 50df3b6

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,11 +1168,11 @@ public function testBug13770(): void
11681168
$this->analyse([__DIR__ . '/data/bug-13770.php'], [
11691169
[
11701170
'Offset int<1, max> might not exist on non-empty-list<int>.',
1171-
40,
1171+
53,
11721172
],
11731173
[
11741174
'Offset int might not exist on list<int>.',
1175-
53,
1175+
66,
11761176
],
11771177
]);
11781178
}

tests/PHPStan/Rules/Arrays/data/bug-13770.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ public function positiveIntLessThanCount(array $array, int $index): int
1717
return 0;
1818
}
1919

20+
/**
21+
* @param list<int> $array
22+
* @param positive-int $index
23+
*/
24+
public function positiveIntLessThanCountInversed(array $array, int $index): int
25+
{
26+
if (count($array) > $index) {
27+
return $array[$index]; // should not report
28+
}
29+
30+
return 0;
31+
}
32+
2033
/**
2134
* @param list<int> $array
2235
* @param int<0, max> $index

0 commit comments

Comments
 (0)