Skip to content

Commit ef4eb6a

Browse files
committed
ExpressionResult isAlwaysTerminating is consistent with StatementResult
1 parent 523b7d4 commit ef4eb6a

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

src/Analyser/ExpressionResult.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ final class ExpressionResult
2424
public function __construct(
2525
private MutatingScope $scope,
2626
private bool $hasYield,
27+
private bool $isAlwaysTerminating,
2728
private array $throwPoints,
2829
private array $impurePoints,
2930
?callable $truthyScopeCallback = null,
3031
?callable $falseyScopeCallback = null,
31-
private bool $isAlwaysTerminating = false,
3232
)
3333
{
3434
$this->truthyScopeCallback = $truthyScopeCallback;

src/Analyser/NodeScopeResolver.php

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,7 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
19131913
$nodeCallback($node, $scope);
19141914
},
19151915
ExpressionContext::createDeep(),
1916-
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, [], []),
1916+
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, false, [], []),
19171917
false,
19181918
)->getScope();
19191919
} elseif ($var instanceof PropertyFetch) {
@@ -2473,7 +2473,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context): Exp
24732473
$scope = $scope->exitExpressionAssign($expr->expr);
24742474
}
24752475

2476-
return new ExpressionResult($scope, $hasYield, $throwPoints, $impurePoints, isAlwaysTerminating: $isAlwaysTerminating);
2476+
return new ExpressionResult($scope, $hasYield, $isAlwaysTerminating, $throwPoints, $impurePoints);
24772477
},
24782478
true,
24792479
);
@@ -2511,9 +2511,9 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context): Exp
25112511
return new ExpressionResult(
25122512
$result->getScope()->mergeWith($originalScope),
25132513
$result->hasYield(),
2514+
$result->isAlwaysTerminating(),
25142515
$result->getThrowPoints(),
25152516
$result->getImpurePoints(),
2516-
isAlwaysTerminating: $result->isAlwaysTerminating(),
25172517
);
25182518
}
25192519

@@ -2930,6 +2930,7 @@ static function (): void {
29302930
return new ExpressionResult(
29312931
$scope,
29322932
$exprResult->hasYield(),
2933+
false,
29332934
$exprResult->getThrowPoints(),
29342935
$exprResult->getImpurePoints(),
29352936
static fn (): MutatingScope => $scope->filterByTruthyValue($expr),
@@ -3132,6 +3133,7 @@ static function (): void {
31323133
return new ExpressionResult(
31333134
$scope,
31343135
$exprResult->hasYield(),
3136+
false,
31353137
$exprResult->getThrowPoints(),
31363138
$exprResult->getImpurePoints(),
31373139
static fn (): MutatingScope => $scope->filterByTruthyValue($expr),
@@ -3169,6 +3171,7 @@ static function (): void {
31693171
return new ExpressionResult(
31703172
$processClosureResult->getScope(),
31713173
false,
3174+
false,
31723175
[],
31733176
[],
31743177
);
@@ -3177,6 +3180,7 @@ static function (): void {
31773180
return new ExpressionResult(
31783181
$result->getScope(),
31793182
$result->hasYield(),
3183+
false,
31803184
[],
31813185
[],
31823186
);
@@ -3273,6 +3277,7 @@ static function (): void {
32733277
return new ExpressionResult(
32743278
$leftMergedWithRightScope,
32753279
$leftResult->hasYield() || $rightResult->hasYield(),
3280+
false,
32763281
array_merge($leftResult->getThrowPoints(), $rightResult->getThrowPoints()),
32773282
array_merge($leftResult->getImpurePoints(), $rightResult->getImpurePoints()),
32783283
static fn (): MutatingScope => $rightResult->getScope()->filterByTruthyValue($expr),
@@ -3293,6 +3298,7 @@ static function (): void {
32933298
return new ExpressionResult(
32943299
$leftMergedWithRightScope,
32953300
$leftResult->hasYield() || $rightResult->hasYield(),
3301+
false,
32963302
array_merge($leftResult->getThrowPoints(), $rightResult->getThrowPoints()),
32973303
array_merge($leftResult->getImpurePoints(), $rightResult->getImpurePoints()),
32983304
static fn (): MutatingScope => $leftMergedWithRightScope->filterByTruthyValue($expr),
@@ -3491,7 +3497,7 @@ static function (): void {
34913497
}
34923498
} elseif ($expr instanceof List_) {
34933499
// only in assign and foreach, processed elsewhere
3494-
return new ExpressionResult($scope, false, [], []);
3500+
return new ExpressionResult($scope, false, false, [], []);
34953501
} elseif ($expr instanceof New_) {
34963502
$parametersAcceptor = null;
34973503
$constructorReflection = null;
@@ -3643,7 +3649,7 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
36433649
$nodeCallback($node, $scope);
36443650
},
36453651
$context,
3646-
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, [], []),
3652+
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, false, [], []),
36473653
false,
36483654
)->getScope();
36493655
} elseif ($expr instanceof Ternary) {
@@ -3688,6 +3694,7 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
36883694
return new ExpressionResult(
36893695
$finalScope,
36903696
$ternaryCondResult->hasYield(),
3697+
false,
36913698
$throwPoints,
36923699
$impurePoints,
36933700
static fn (): MutatingScope => $finalScope->filterByTruthyValue($expr),
@@ -4017,11 +4024,11 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
40174024
return new ExpressionResult(
40184025
$scope,
40194026
$hasYield,
4027+
$isAlwaysTerminating,
40204028
$throwPoints,
40214029
$impurePoints,
40224030
static fn (): MutatingScope => $scope->filterByTruthyValue($expr),
40234031
static fn (): MutatingScope => $scope->filterByFalseyValue($expr),
4024-
$isAlwaysTerminating,
40254032
);
40264033
}
40274034

@@ -4738,7 +4745,7 @@ private function processArrowFunctionNode(
47384745
$nodeCallback(new InArrowFunctionNode($arrowFunctionType, $expr), $arrowFunctionScope);
47394746
$exprResult = $this->processExprNode($stmt, $expr->expr, $arrowFunctionScope, $nodeCallback, ExpressionContext::createTopLevel());
47404747

4741-
return new ExpressionResult($scope, false, $exprResult->getThrowPoints(), $exprResult->getImpurePoints());
4748+
return new ExpressionResult($scope, false, false, $exprResult->getThrowPoints(), $exprResult->getImpurePoints());
47424749
}
47434750

47444751
/**
@@ -5260,7 +5267,7 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
52605267
$nodeCallback($node, $scope);
52615268
},
52625269
$context,
5263-
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, [], []),
5270+
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, false, [], []),
52645271
true,
52655272
);
52665273
$scope = $result->getScope();
@@ -5293,7 +5300,7 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
52935300
}
52945301
}
52955302

5296-
return new ExpressionResult($scope, $hasYield, $throwPoints, $impurePoints, isAlwaysTerminating: $isAlwaysTerminating);
5303+
return new ExpressionResult($scope, $hasYield, $isAlwaysTerminating, $throwPoints, $impurePoints);
52975304
}
52985305

52995306
/**
@@ -5852,7 +5859,7 @@ static function (): void {
58525859
new GetOffsetValueTypeExpr($assignedExpr, $dimExpr),
58535860
$nodeCallback,
58545861
$context,
5855-
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, [], []),
5862+
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, false, [], []),
58565863
$enterExpressionAssign,
58575864
);
58585865
$scope = $result->getScope();
@@ -5938,7 +5945,7 @@ static function (): void {
59385945
}
59395946
}
59405947

5941-
return new ExpressionResult($scope, $hasYield, $throwPoints, $impurePoints, isAlwaysTerminating: $isAlwaysTerminating);
5948+
return new ExpressionResult($scope, $hasYield, $isAlwaysTerminating, $throwPoints, $impurePoints);
59425949
}
59435950

59445951
/**
@@ -6248,7 +6255,7 @@ private function enterForeach(MutatingScope $scope, MutatingScope $originalScope
62486255
static function (): void {
62496256
},
62506257
ExpressionContext::createDeep(),
6251-
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, [], []),
6258+
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, false, [], []),
62526259
true,
62536260
)->getScope();
62546261
$vars = $this->getAssignedVariables($stmt->valueVar);
@@ -6266,7 +6273,7 @@ static function (): void {
62666273
static function (): void {
62676274
},
62686275
ExpressionContext::createDeep(),
6269-
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, [], []),
6276+
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, false, [], []),
62706277
true,
62716278
)->getScope();
62726279
$vars = array_merge($vars, $this->getAssignedVariables($stmt->keyVar));

0 commit comments

Comments
 (0)