Skip to content

Commit 50abf2a

Browse files
committed
Keep list on unset() with nested dim-fetch
1 parent cdf4b4d commit 50abf2a

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

src/Type/Accessory/AccessoryArrayListType.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ public function setExistingOffsetValueType(Type $offsetType, Type $valueType): T
160160
return $this;
161161
}
162162

163+
if (
164+
$valueType->isArray()->yes()
165+
&& IntegerRangeType::fromInterval(0, null)->isSuperTypeOf($offsetType)->yes()
166+
) {
167+
return $this;
168+
}
169+
163170
return new ErrorType();
164171
}
165172

tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,11 @@ public function testBug1O580(): void
12241224
}
12251225

12261226
#[RequiresPhp('>= 8.0')]
1227+
public function testBug12927(): void
1228+
{
1229+
$this->analyse([__DIR__ . '/data/bug-12927.php'], []);
1230+
}
1231+
12271232
public function testBug4443(): void
12281233
{
12291234
$this->analyse([__DIR__ . '/data/bug-4443.php'], [
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Bug12927;
4+
5+
class HelloWorld
6+
{
7+
/**
8+
* @param list<array{abc: string}> $list
9+
* @return list<array<string>>
10+
*/
11+
public function sayHello(array $list): array
12+
{
13+
foreach($list as $k => $v) {
14+
unset($list[$k]['abc']);
15+
}
16+
return $list;
17+
}
18+
}

tests/PHPStan/Rules/Variables/ParameterOutAssignedTypeRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testRule(): void
4343
47,
4444
],
4545
[
46-
'Parameter &$p @param-out type of method ParameterOutAssignedType\Foo::doBaz3() expects list<list<int>>, array<int<0, max>, array<int<0, max>, int>> given.',
46+
'Parameter &$p @param-out type of method ParameterOutAssignedType\Foo::doBaz3() expects list<list<int>>, list<array<int<0, max>, int>> given.',
4747
56,
4848
],
4949
[

0 commit comments

Comments
 (0)