Skip to content

Commit ef319f3

Browse files
committed
Keep list on unset() with nested dim-fetch
1 parent b7bef97 commit ef319f3

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
@@ -1232,6 +1232,11 @@ public function testBug1O580(): void
12321232
]);
12331233
}
12341234

1235+
public function testBug12927(): void
1236+
{
1237+
$this->analyse([__DIR__ . '/data/bug-12927.php'], []);
1238+
}
1239+
12351240
public function testBug4443(): void
12361241
{
12371242
if (PHP_VERSION_ID < 80000) {
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)