Skip to content

Commit e04f711

Browse files
phpstan-botondrejmirtesstaabm
committed
Fix phpstan/phpstan#14019: Assignment in a key of array destructuring is ignored (phpstan#5164)
Co-authored-by: ondrejmirtes <104888+ondrejmirtes@users.noreply.github.com> Co-authored-by: Markus Staab <markus.staab@redaxo.de>
1 parent 6df9758 commit e04f711

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/Analyser/ExprHandler/AssignHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ public function processAssignVar(
688688
$throwPoints = array_merge($throwPoints, $keyResult->getThrowPoints());
689689
$impurePoints = array_merge($impurePoints, $keyResult->getImpurePoints());
690690
$isAlwaysTerminating = $isAlwaysTerminating || $keyResult->isAlwaysTerminating();
691-
// no need for $keyResult->getScope()
691+
$scope = $keyResult->getScope();
692692
}
693693

694694
if ($arrayItem->key === null) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug14019;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
[($a = 'foo') => $b] = ['foo' => 1];
8+
9+
assertType("'foo'", $a);
10+
assertType('1', $b);

tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,16 @@ public function testBug6830(): void
13931393
$this->analyse([__DIR__ . '/data/bug-6830.php'], []);
13941394
}
13951395

1396+
public function testBug14019(): void
1397+
{
1398+
$this->cliArgumentsVariablesRegistered = true;
1399+
$this->polluteScopeWithLoopInitialAssignments = false;
1400+
$this->checkMaybeUndefinedVariables = true;
1401+
$this->polluteScopeWithAlwaysIterableForeach = true;
1402+
1403+
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-14019.php'], []);
1404+
}
1405+
13961406
public function testBug14117(): void
13971407
{
13981408
$this->cliArgumentsVariablesRegistered = true;

0 commit comments

Comments
 (0)