Skip to content

Commit 3db8662

Browse files
committed
Store inc/dec results before the virtual assign emits assignment nodes
1 parent 861fcb6 commit 3db8662

4 files changed

Lines changed: 56 additions & 0 deletions

File tree

‎src/Analyser/ExprHandler/PostDecHandler.php‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
4040
{
4141
$varResult = $nodeScopeResolver->processExprNode($stmt, $expr->var, $scope, $storage, $nodeCallback, $context->enterDeep());
4242

43+
// processVirtualAssign() emits nodes (PropertyAssignNode) whose rules ask
44+
// about this whole expression - store a before-scope anchored result
45+
// first so those asks answer from the storage; processExprNode()
46+
// overwrites it with the final result after this handler returns
47+
$nodeScopeResolver->storeExpressionResult($storage, $expr, $this->expressionResultFactory->create(
48+
$varResult->getScope(),
49+
$scope,
50+
$expr,
51+
hasYield: false,
52+
isAlwaysTerminating: false,
53+
throwPoints: [],
54+
impurePoints: [],
55+
));
56+
4357
return $this->expressionResultFactory->create(
4458
$nodeScopeResolver->processVirtualAssign(
4559
$varResult->getScope(),

‎src/Analyser/ExprHandler/PostIncHandler.php‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
4040
{
4141
$varResult = $nodeScopeResolver->processExprNode($stmt, $expr->var, $scope, $storage, $nodeCallback, $context->enterDeep());
4242

43+
// processVirtualAssign() emits nodes (PropertyAssignNode) whose rules ask
44+
// about this whole expression - store a before-scope anchored result
45+
// first so those asks answer from the storage; processExprNode()
46+
// overwrites it with the final result after this handler returns
47+
$nodeScopeResolver->storeExpressionResult($storage, $expr, $this->expressionResultFactory->create(
48+
$varResult->getScope(),
49+
$scope,
50+
$expr,
51+
hasYield: false,
52+
isAlwaysTerminating: false,
53+
throwPoints: [],
54+
impurePoints: [],
55+
));
56+
4357
return $this->expressionResultFactory->create(
4458
$nodeScopeResolver->processVirtualAssign(
4559
$varResult->getScope(),

‎src/Analyser/ExprHandler/PreDecHandler.php‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,20 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
103103
{
104104
$varResult = $nodeScopeResolver->processExprNode($stmt, $expr->var, $scope, $storage, $nodeCallback, $context->enterDeep());
105105

106+
// processVirtualAssign() emits nodes (PropertyAssignNode) whose rules ask
107+
// about this whole expression - store a before-scope anchored result
108+
// first so those asks answer from the storage; processExprNode()
109+
// overwrites it with the final result after this handler returns
110+
$nodeScopeResolver->storeExpressionResult($storage, $expr, $this->expressionResultFactory->create(
111+
$varResult->getScope(),
112+
$scope,
113+
$expr,
114+
hasYield: false,
115+
isAlwaysTerminating: false,
116+
throwPoints: [],
117+
impurePoints: [],
118+
));
119+
106120
return $this->expressionResultFactory->create(
107121
$nodeScopeResolver->processVirtualAssign(
108122
$varResult->getScope(),

‎src/Analyser/ExprHandler/PreIncHandler.php‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,20 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
104104
{
105105
$varResult = $nodeScopeResolver->processExprNode($stmt, $expr->var, $scope, $storage, $nodeCallback, $context->enterDeep());
106106

107+
// processVirtualAssign() emits nodes (PropertyAssignNode) whose rules ask
108+
// about this whole expression - store a before-scope anchored result
109+
// first so those asks answer from the storage; processExprNode()
110+
// overwrites it with the final result after this handler returns
111+
$nodeScopeResolver->storeExpressionResult($storage, $expr, $this->expressionResultFactory->create(
112+
$varResult->getScope(),
113+
$scope,
114+
$expr,
115+
hasYield: false,
116+
isAlwaysTerminating: false,
117+
throwPoints: [],
118+
impurePoints: [],
119+
));
120+
107121
return $this->expressionResultFactory->create(
108122
$nodeScopeResolver->processVirtualAssign(
109123
$varResult->getScope(),

0 commit comments

Comments
 (0)