Skip to content

Commit 95d2866

Browse files
authored
Merge branch refs/heads/2.1.x into 2.2.x
2 parents 95584e1 + 2295fee commit 95d2866

File tree

5 files changed

+83
-1
lines changed

5 files changed

+83
-1
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6297,7 +6297,7 @@ private function processAssignVar(
62976297

62986298
if ($varType->isArray()->yes() || !(new ObjectType(ArrayAccess::class))->isSuperTypeOf($varType)->yes()) {
62996299
if ($var instanceof Variable && is_string($var->name)) {
6300-
$this->callNodeCallback($nodeCallback, new VariableAssignNode($var, $assignedPropertyExpr), $scopeBeforeAssignEval, $storage);
6300+
$this->callNodeCallback($nodeCallback, new VariableAssignNode($var, new TypeExpr($valueToWrite)), $scopeBeforeAssignEval, $storage);
63016301
$scope = $scope->assignVariable($var->name, $valueToWrite, $nativeValueToWrite, TrinaryLogic::createYes());
63026302
} else {
63036303
if ($var instanceof PropertyFetch || $var instanceof StaticPropertyFetch) {

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ private static function findTestFiles(): iterable
253253
yield __DIR__ . '/../Rules/Arrays/data/narrow-superglobal.php';
254254
yield __DIR__ . '/../Rules/Methods/data/bug-12927.php';
255255
yield __DIR__ . '/../Rules/Properties/data/bug-14012.php';
256+
yield __DIR__ . '/../Rules/Variables/data/bug-14124.php';
257+
yield __DIR__ . '/../Rules/Variables/data/bug-14124b.php';
256258
}
257259

258260
/**

tests/PHPStan/Rules/Variables/ParameterOutAssignedTypeRuleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,14 @@ public function testBug12754(): void
8181
$this->analyse([__DIR__ . '/data/bug-12754.php'], []);
8282
}
8383

84+
public function testBug14124(): void
85+
{
86+
$this->analyse([__DIR__ . '/data/bug-14124.php'], []);
87+
}
88+
89+
public function testBug14124b(): void
90+
{
91+
$this->analyse([__DIR__ . '/data/bug-14124b.php'], []);
92+
}
93+
8494
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Bug14124;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @param array<string, list<string>> $convert
9+
* @param-out array<string, list<string>> $convert
10+
*/
11+
function example3a(array &$convert): void
12+
{
13+
foreach ($convert as &$inner) {
14+
foreach ($inner as &$val) {
15+
$val = strtoupper($val);
16+
}
17+
}
18+
assertType('array<string, list<string>>', $convert);
19+
}
20+
21+
/**
22+
* @param array<string, list<string>> $convert
23+
* @param-out array<string, list<string>> $convert
24+
*/
25+
function example3b(array &$convert): void
26+
{
27+
foreach ($convert as $outerKey => $inner) {
28+
foreach ($inner as $key => $val) {
29+
$convert[$outerKey][$key] = strtoupper($val);
30+
}
31+
}
32+
assertType('array<string, list<string>>', $convert);
33+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Bug14124b;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @param array<string, list<list<string>>> $convert
9+
* @param-out array<string, list<list<string>>> $convert
10+
*/
11+
function example3a(array &$convert): void
12+
{
13+
foreach ($convert as &$inner) {
14+
foreach ($inner as &$val) {
15+
foreach ($val as &$val2) {
16+
$val2 = strtoupper($val2);
17+
}
18+
}
19+
}
20+
assertType('array<string, list<list<string>>>', $convert);
21+
}
22+
23+
/**
24+
* @param array<string, list<list<string>>> $convert
25+
* @param-out array<string, list<list<string>>> $convert
26+
*/
27+
function example3b(array &$convert): void
28+
{
29+
foreach ($convert as $outerKey => $inner) {
30+
foreach ($inner as $key => $val) {
31+
foreach ($val as $key2 => $val2) {
32+
$convert[$outerKey][$key][$key2] = strtoupper($val);
33+
}
34+
}
35+
}
36+
assertType('array<string, list<list<string>>>', $convert);
37+
}

0 commit comments

Comments
 (0)