Skip to content

Commit 37d5313

Browse files
committed
another test
1 parent e25dfea commit 37d5313

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

src/Analyser/NodeScopeResolver.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -5771,9 +5771,10 @@ private function produceArrayDimFetchAssignValueToWrite(array $offsetTypes, Type
57715771
$offsetValueTypeStack[] = [$offsetValueType, $has];
57725772
}
57735773

5774-
foreach (array_reverse($offsetTypes) as $i => [$offsetType]) {
5775-
/** @var Type $offsetValueType */
5776-
[$offsetValueType, $has] = array_pop($offsetValueTypeStack);
5774+
foreach (array_reverse($offsetTypes) as [$offsetType]) {
5775+
/** @var array{Type, TrinaryLogic} $stackItem */
5776+
$stackItem = array_pop($offsetValueTypeStack);
5777+
[$offsetValueType, $has] = $stackItem;
57775778
if (
57785779
!$offsetValueType instanceof MixedType
57795780
&& !$offsetValueType->isConstantArray()->yes()

tests/PHPStan/Analyser/data/bug-10922.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ public function sayHello3(array $array): void
3838
foreach ($array as $key => $item) {
3939
$array[$key]['bar'] = '';
4040
}
41-
assertType("non-empty-array<string, array{foo: string, bar: ''}>", $array);
41+
assertType("non-empty-array<string, array{foo: string, bar?: ''}>", $array);
4242
}
4343
}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug6173;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class HelloWorld
8+
{
9+
/**
10+
* @param int[] $ids1
11+
* @param int[] $ids2
12+
*/
13+
public function sayHello(array $ids1, array $ids2): bool
14+
{
15+
$res = [];
16+
foreach ($ids1 as $id) {
17+
$res[$id]['foo'] = $id;
18+
}
19+
20+
foreach ($ids2 as $id) {
21+
$res[$id]['bar'] = $id;
22+
}
23+
24+
assertType('array<int, non-empty-array{foo?: int, bar?: int}>', $res);
25+
26+
return true;
27+
}
28+
}

0 commit comments

Comments
 (0)