Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6297,7 +6297,7 @@ private function processAssignVar(

if ($varType->isArray()->yes() || !(new ObjectType(ArrayAccess::class))->isSuperTypeOf($varType)->yes()) {
if ($var instanceof Variable && is_string($var->name)) {
$this->callNodeCallback($nodeCallback, new VariableAssignNode($var, $assignedPropertyExpr), $scopeBeforeAssignEval, $storage);
$this->callNodeCallback($nodeCallback, new VariableAssignNode($var, new TypeExpr($valueToWrite)), $scopeBeforeAssignEval, $storage);
$scope = $scope->assignVariable($var->name, $valueToWrite, $nativeValueToWrite, TrinaryLogic::createYes());
} else {
if ($var instanceof PropertyFetch || $var instanceof StaticPropertyFetch) {
Expand Down
2 changes: 2 additions & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ private static function findTestFiles(): iterable
yield __DIR__ . '/../Rules/Arrays/data/narrow-superglobal.php';
yield __DIR__ . '/../Rules/Methods/data/bug-12927.php';
yield __DIR__ . '/../Rules/Properties/data/bug-14012.php';
yield __DIR__ . '/../Rules/Variables/data/bug-14124.php';
yield __DIR__ . '/../Rules/Variables/data/bug-14124b.php';
}

/**
Expand Down
10 changes: 10 additions & 0 deletions tests/PHPStan/Rules/Variables/ParameterOutAssignedTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,14 @@ public function testBug12754(): void
$this->analyse([__DIR__ . '/data/bug-12754.php'], []);
}

public function testBug14124(): void
{
$this->analyse([__DIR__ . '/data/bug-14124.php'], []);
}

public function testBug14124b(): void
{
$this->analyse([__DIR__ . '/data/bug-14124b.php'], []);
}

}
33 changes: 33 additions & 0 deletions tests/PHPStan/Rules/Variables/data/bug-14124.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Bug14124;

use function PHPStan\Testing\assertType;

/**
* @param array<string, list<string>> $convert
* @param-out array<string, list<string>> $convert
*/
function example3a(array &$convert): void
{
foreach ($convert as &$inner) {
foreach ($inner as &$val) {
$val = strtoupper($val);
}
}
assertType('array<string, list<string>>', $convert);
}

/**
* @param array<string, list<string>> $convert
* @param-out array<string, list<string>> $convert
*/
function example3b(array &$convert): void
{
foreach ($convert as $outerKey => $inner) {
foreach ($inner as $key => $val) {
$convert[$outerKey][$key] = strtoupper($val);
}
}
assertType('array<string, list<string>>', $convert);
}
37 changes: 37 additions & 0 deletions tests/PHPStan/Rules/Variables/data/bug-14124b.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Bug14124b;

use function PHPStan\Testing\assertType;

/**
* @param array<string, list<list<string>>> $convert
* @param-out array<string, list<list<string>>> $convert
*/
function example3a(array &$convert): void
{
foreach ($convert as &$inner) {
foreach ($inner as &$val) {
foreach ($val as &$val2) {
$val2 = strtoupper($val2);
}
}
}
assertType('array<string, list<list<string>>>', $convert);
}

/**
* @param array<string, list<list<string>>> $convert
* @param-out array<string, list<list<string>>> $convert
*/
function example3b(array &$convert): void
{
foreach ($convert as $outerKey => $inner) {
foreach ($inner as $key => $val) {
foreach ($val as $key2 => $val2) {
$convert[$outerKey][$key][$key2] = strtoupper($val);
}
}
}
assertType('array<string, list<list<string>>>', $convert);
}
Loading