Skip to content

Commit 77b49bf

Browse files
More
1 parent f1d04af commit 77b49bf

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

tests/PHPStan/Analyser/nsrt/array-is-list-unset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function () {
1919
assertType('true', array_is_list($a));
2020
unset($a[2]);
2121
assertType('array{1, 2}', $a);
22-
assertType('false', array_is_list($a)); // Could be true
22+
assertType('false', array_is_list($a));
2323
$a[] = 4;
2424
assertType('array{0: 1, 1: 2, 3: 4}', $a);
2525
assertType('false', array_is_list($a));

tests/PHPStan/Analyser/nsrt/bug-14177.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function testUnset2OnArray(array $b): void
151151
{
152152
assertType('bool', array_is_list($b));
153153
unset($b[2]);
154-
assertType('false', array_is_list($b)); // Could be true
154+
assertType('false', array_is_list($b));
155155
$b[] = 'foo';
156156
assertType('false', array_is_list($b));
157157
}
@@ -167,4 +167,37 @@ public function testUnset3OnArray(array $b): void
167167
$b[] = 'foo';
168168
assertType('bool', array_is_list($b)); // Could be false
169169
}
170+
171+
/**
172+
* @param list{0: string, 1: string, 2?: string, 3?: string} $a
173+
* @param list{0: string, 1?: string, 2?: string, 3?: string} $b
174+
* @param list{0: string, 1?: string, 2?: string, 3: string} $c
175+
* @param 1|2 $int
176+
*/
177+
public function testUnsetNonConstant(array $a, array $b, array $c, int $int): void
178+
{
179+
assertType('true', array_is_list($a));
180+
assertType('true', array_is_list($b));
181+
assertType('true', array_is_list($c));
182+
unset($a[$int]);
183+
unset($b[$int]);
184+
unset($c[$int]);
185+
assertType('false', array_is_list($a));
186+
assertType('bool', array_is_list($b));
187+
assertType('bool', array_is_list($c));
188+
}
189+
190+
/**
191+
* @param list{0?: string, 1?: string, 2?: string, 3?: string} $a
192+
* @param list{0: string, 1?: string, 2?: string, 3?: string} $b
193+
*/
194+
public function testUnsetInt(array $a, array $b, array $c, int $int): void
195+
{
196+
assertType('true', array_is_list($a));
197+
assertType('true', array_is_list($b));
198+
unset($a[$int]);
199+
unset($b[$int]);
200+
assertType('bool', array_is_list($a));
201+
assertType('false', array_is_list($b));
202+
}
170203
}

0 commit comments

Comments
 (0)