Skip to content

Commit 4b48990

Browse files
phpstan-botclaude
andcommitted
Split bug-10862 test into PHP 8.2 and PHP 8.3 variants
Separate version-specific assertions into two test files with lint version constraints instead of a single file. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 05d88e7 commit 4b48990

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php // lint <= 8.2
2+
3+
declare(strict_types = 1);
4+
5+
namespace Bug10862Php82;
6+
7+
use function PHPStan\Testing\assertType;
8+
9+
function () {
10+
$a = [];
11+
$a[-4] = 1;
12+
$a[] = 2;
13+
14+
assertType('array{-4: 1, 0: 2}', $a); // PHP <=8.2: next key after -4 is 0
15+
assertType('array{-4, 0}', array_keys($a));
16+
};
17+
18+
function () {
19+
$a = [];
20+
$a[-1] = 'x';
21+
$a[] = 'y';
22+
23+
assertType("array{-1: 'x', 0: 'y'}", $a); // PHP <=8.2: next key after -1 is 0
24+
assertType('array{-1, 0}', array_keys($a));
25+
};
26+
27+
function () {
28+
$a = [];
29+
$a[-10] = 'a';
30+
$a[-5] = 'b';
31+
$a[] = 'c';
32+
33+
assertType("array{-10: 'a', -5: 'b', 0: 'c'}", $a); // PHP <=8.2: next key is 0
34+
assertType('array{-10, -5, 0}', array_keys($a));
35+
};
36+
37+
function () {
38+
$a = [];
39+
$a[-3] = 'a';
40+
$a[5] = 'b';
41+
$a[] = 'c';
42+
43+
assertType("array{-3: 'a', 5: 'b', 6: 'c'}", $a); // positive key dominates
44+
assertType('array{-3, 5, 6}', array_keys($a));
45+
};

tests/PHPStan/Analyser/nsrt/bug-10862.php renamed to tests/PHPStan/Analyser/nsrt/bug-10862-php83.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<?php
1+
<?php // lint >= 8.3
22

33
declare(strict_types = 1);
44

5-
namespace Bug10862;
5+
namespace Bug10862Php83;
66

77
use function PHPStan\Testing\assertType;
88

0 commit comments

Comments
 (0)