diff --git a/src/Analyser/ExprHandler/AssignHandler.php b/src/Analyser/ExprHandler/AssignHandler.php index 8fd6a455ea8..89b53c46c23 100644 --- a/src/Analyser/ExprHandler/AssignHandler.php +++ b/src/Analyser/ExprHandler/AssignHandler.php @@ -688,7 +688,7 @@ public function processAssignVar( $throwPoints = array_merge($throwPoints, $keyResult->getThrowPoints()); $impurePoints = array_merge($impurePoints, $keyResult->getImpurePoints()); $isAlwaysTerminating = $isAlwaysTerminating || $keyResult->isAlwaysTerminating(); - // no need for $keyResult->getScope() + $scope = $keyResult->getScope(); } if ($arrayItem->key === null) { diff --git a/tests/PHPStan/Analyser/nsrt/bug-14019.php b/tests/PHPStan/Analyser/nsrt/bug-14019.php new file mode 100644 index 00000000000..407fe643af7 --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/bug-14019.php @@ -0,0 +1,10 @@ + $b] = ['foo' => 1]; + +assertType("'foo'", $a); +assertType('1', $b); diff --git a/tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php b/tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php index d217d5010df..2dde59f1423 100644 --- a/tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php +++ b/tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php @@ -1393,6 +1393,16 @@ public function testBug6830(): void $this->analyse([__DIR__ . '/data/bug-6830.php'], []); } + public function testBug14019(): void + { + $this->cliArgumentsVariablesRegistered = true; + $this->polluteScopeWithLoopInitialAssignments = false; + $this->checkMaybeUndefinedVariables = true; + $this->polluteScopeWithAlwaysIterableForeach = true; + + $this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-14019.php'], []); + } + public function testBug14117(): void { $this->cliArgumentsVariablesRegistered = true;