Skip to content

Commit 93eac04

Browse files
ondrejmirtesphpstan-bot
authored andcommitted
Fix assignment in key of array destructuring being ignored
- Propagate scope from key expression processing in list/array destructuring - Previously the scope result from processing key expressions was discarded, so assignments like `[($a = 'foo') => $b] = [...]` left `$a` undefined - New regression test in tests/PHPStan/Analyser/nsrt/bug-14019.php Closes phpstan/phpstan#14019
1 parent d32efcb commit 93eac04

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

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);

0 commit comments

Comments
 (0)