Skip to content

Commit 3ee593c

Browse files
authored
Merge branch refs/heads/1.10.x into 1.11.x
2 parents 38e31bf + 436bd79 commit 3ee593c

File tree

1 file changed

+34
-41
lines changed

1 file changed

+34
-41
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
use PhpParser\Node\Stmt\If_;
4646
use PhpParser\Node\Stmt\Return_;
4747
use PhpParser\Node\Stmt\Static_;
48-
use PhpParser\Node\Stmt\StaticVar;
4948
use PhpParser\Node\Stmt\Switch_;
5049
use PhpParser\Node\Stmt\Throw_;
5150
use PhpParser\Node\Stmt\TryCatch;
@@ -1549,28 +1548,23 @@ private function processStmtNode(
15491548

15501549
$vars = [];
15511550
foreach ($stmt->vars as $var) {
1552-
$scope = $this->processStmtNode($var, $scope, $nodeCallback, $context)->getScope();
15531551
if (!is_string($var->var->name)) {
1554-
continue;
1552+
throw new ShouldNotHappenException();
15551553
}
15561554

1555+
if ($var->default !== null) {
1556+
$this->processExprNode($var->default, $scope, $nodeCallback, ExpressionContext::createDeep());
1557+
}
1558+
1559+
$scope = $scope->enterExpressionAssign($var->var);
1560+
$this->processExprNode($var->var, $scope, $nodeCallback, ExpressionContext::createDeep());
1561+
$scope = $scope->exitExpressionAssign($var->var);
1562+
1563+
$scope = $scope->assignVariable($var->var->name, new MixedType(), new MixedType());
15571564
$vars[] = $var->var->name;
15581565
}
15591566

15601567
$scope = $this->processVarAnnotation($scope, $vars, $stmt);
1561-
} elseif ($stmt instanceof StaticVar) {
1562-
$hasYield = false;
1563-
$throwPoints = [];
1564-
if (!is_string($stmt->var->name)) {
1565-
throw new ShouldNotHappenException();
1566-
}
1567-
if ($stmt->default !== null) {
1568-
$this->processExprNode($stmt->default, $scope, $nodeCallback, ExpressionContext::createDeep());
1569-
}
1570-
$scope = $scope->enterExpressionAssign($stmt->var);
1571-
$this->processExprNode($stmt->var, $scope, $nodeCallback, ExpressionContext::createDeep());
1572-
$scope = $scope->exitExpressionAssign($stmt->var);
1573-
$scope = $scope->assignVariable($stmt->var->name, new MixedType(), new MixedType());
15741568
} elseif ($stmt instanceof Node\Stmt\Const_) {
15751569
$hasYield = false;
15761570
$throwPoints = [];
@@ -2462,10 +2456,6 @@ static function (): void {
24622456
}
24632457
} elseif ($expr instanceof Expr\Closure) {
24642458
return $this->processClosureNode($expr, $scope, $nodeCallback, $context, null);
2465-
} elseif ($expr instanceof Expr\ClosureUse) {
2466-
$this->processExprNode($expr->var, $scope, $nodeCallback, $context);
2467-
$hasYield = false;
2468-
$throwPoints = [];
24692459
} elseif ($expr instanceof Expr\ArrowFunction) {
24702460
return $this->processArrowFunctionNode($expr, $scope, $nodeCallback, $context, null);
24712461
} elseif ($expr instanceof ErrorSuppress) {
@@ -2514,25 +2504,20 @@ static function (): void {
25142504
if ($arrayItem === null) {
25152505
continue;
25162506
}
2517-
$result = $this->processExprNode($arrayItem, $scope, $nodeCallback, $context->enterDeep());
2518-
$hasYield = $hasYield || $result->hasYield();
2519-
$throwPoints = array_merge($throwPoints, $result->getThrowPoints());
2520-
$scope = $result->getScope();
2507+
$nodeCallback($arrayItem, $scope);
2508+
if ($arrayItem->key !== null) {
2509+
$keyResult = $this->processExprNode($arrayItem->key, $scope, $nodeCallback, $context->enterDeep());
2510+
$hasYield = $hasYield || $keyResult->hasYield();
2511+
$throwPoints = array_merge($throwPoints, $keyResult->getThrowPoints());
2512+
$scope = $keyResult->getScope();
2513+
}
2514+
2515+
$valueResult = $this->processExprNode($arrayItem->value, $scope, $nodeCallback, $context->enterDeep());
2516+
$hasYield = $hasYield || $valueResult->hasYield();
2517+
$throwPoints = array_merge($throwPoints, $valueResult->getThrowPoints());
2518+
$scope = $valueResult->getScope();
25212519
}
25222520
$nodeCallback(new LiteralArrayNode($expr, $itemNodes), $scope);
2523-
} elseif ($expr instanceof ArrayItem) {
2524-
$hasYield = false;
2525-
$throwPoints = [];
2526-
if ($expr->key !== null) {
2527-
$result = $this->processExprNode($expr->key, $scope, $nodeCallback, $context->enterDeep());
2528-
$hasYield = $result->hasYield();
2529-
$throwPoints = $result->getThrowPoints();
2530-
$scope = $result->getScope();
2531-
}
2532-
$result = $this->processExprNode($expr->value, $scope, $nodeCallback, $context->enterDeep());
2533-
$hasYield = $hasYield || $result->hasYield();
2534-
$throwPoints = array_merge($throwPoints, $result->getThrowPoints());
2535-
$scope = $result->getScope();
25362521
} elseif ($expr instanceof BooleanAnd || $expr instanceof BinaryOp\LogicalAnd) {
25372522
$leftResult = $this->processExprNode($expr->left, $scope, $nodeCallback, $context->enterDeep());
25382523
$rightResult = $this->processExprNode($expr->right, $leftResult->getTruthyScope(), $nodeCallback, $context);
@@ -3409,7 +3394,7 @@ private function processClosureNode(
34093394
$scope = $scope->assignVariable($inAssignRightSideVariableName, $variableType, $variableNativeType);
34103395
}
34113396
}
3412-
$this->processExprNode($use, $useScope, $nodeCallback, $context);
3397+
$this->processExprNode($use->var, $useScope, $nodeCallback, $context);
34133398
if (!$use->byRef) {
34143399
continue;
34153400
}
@@ -4116,9 +4101,17 @@ static function (): void {
41164101
$itemScope = $itemScope->enterExpressionAssign($arrayItem->value);
41174102
}
41184103
$itemScope = $this->lookForSetAllowedUndefinedExpressions($itemScope, $arrayItem->value);
4119-
$itemResult = $this->processExprNode($arrayItem, $itemScope, $nodeCallback, $context->enterDeep());
4120-
$hasYield = $hasYield || $itemResult->hasYield();
4121-
$throwPoints = array_merge($throwPoints, $itemResult->getThrowPoints());
4104+
$nodeCallback($arrayItem, $itemScope);
4105+
if ($arrayItem->key !== null) {
4106+
$keyResult = $this->processExprNode($arrayItem->key, $itemScope, $nodeCallback, $context->enterDeep());
4107+
$hasYield = $hasYield || $keyResult->hasYield();
4108+
$throwPoints = array_merge($throwPoints, $keyResult->getThrowPoints());
4109+
$itemScope = $keyResult->getScope();
4110+
}
4111+
4112+
$valueResult = $this->processExprNode($arrayItem->value, $itemScope, $nodeCallback, $context->enterDeep());
4113+
$hasYield = $hasYield || $valueResult->hasYield();
4114+
$throwPoints = array_merge($throwPoints, $valueResult->getThrowPoints());
41224115

41234116
if ($arrayItem->key === null) {
41244117
$dimExpr = new Node\Scalar\LNumber($i);

0 commit comments

Comments
 (0)