Skip to content

Commit 5e5878f

Browse files
committed
ExpressionResult isAlwaysTerminating is consistent with StatementResult
1 parent 984f48f commit 5e5878f

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

@@ -2931,6 +2931,7 @@ static function (): void {
29312931
return new ExpressionResult(
29322932
$scope,
29332933
$exprResult->hasYield(),
2934+
false,
29342935
$exprResult->getThrowPoints(),
29352936
$exprResult->getImpurePoints(),
29362937
static fn (): MutatingScope => $scope->filterByTruthyValue($expr),
@@ -3133,6 +3134,7 @@ static function (): void {
31333134
return new ExpressionResult(
31343135
$scope,
31353136
$exprResult->hasYield(),
3137+
false,
31363138
$exprResult->getThrowPoints(),
31373139
$exprResult->getImpurePoints(),
31383140
static fn (): MutatingScope => $scope->filterByTruthyValue($expr),
@@ -3170,6 +3172,7 @@ static function (): void {
31703172
return new ExpressionResult(
31713173
$processClosureResult->getScope(),
31723174
false,
3175+
false,
31733176
[],
31743177
[],
31753178
);
@@ -3178,6 +3181,7 @@ static function (): void {
31783181
return new ExpressionResult(
31793182
$result->getScope(),
31803183
$result->hasYield(),
3184+
false,
31813185
[],
31823186
[],
31833187
);
@@ -3274,6 +3278,7 @@ static function (): void {
32743278
return new ExpressionResult(
32753279
$leftMergedWithRightScope,
32763280
$leftResult->hasYield() || $rightResult->hasYield(),
3281+
false,
32773282
array_merge($leftResult->getThrowPoints(), $rightResult->getThrowPoints()),
32783283
array_merge($leftResult->getImpurePoints(), $rightResult->getImpurePoints()),
32793284
static fn (): MutatingScope => $rightResult->getScope()->filterByTruthyValue($expr),
@@ -3294,6 +3299,7 @@ static function (): void {
32943299
return new ExpressionResult(
32953300
$leftMergedWithRightScope,
32963301
$leftResult->hasYield() || $rightResult->hasYield(),
3302+
false,
32973303
array_merge($leftResult->getThrowPoints(), $rightResult->getThrowPoints()),
32983304
array_merge($leftResult->getImpurePoints(), $rightResult->getImpurePoints()),
32993305
static fn (): MutatingScope => $leftMergedWithRightScope->filterByTruthyValue($expr),
@@ -3492,7 +3498,7 @@ static function (): void {
34923498
}
34933499
} elseif ($expr instanceof List_) {
34943500
// only in assign and foreach, processed elsewhere
3495-
return new ExpressionResult($scope, false, [], []);
3501+
return new ExpressionResult($scope, false, false, [], []);
34963502
} elseif ($expr instanceof New_) {
34973503
$parametersAcceptor = null;
34983504
$constructorReflection = null;
@@ -3644,7 +3650,7 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
36443650
$nodeCallback($node, $scope);
36453651
},
36463652
$context,
3647-
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, [], []),
3653+
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, false, [], []),
36483654
false,
36493655
)->getScope();
36503656
} elseif ($expr instanceof Ternary) {
@@ -3689,6 +3695,7 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
36893695
return new ExpressionResult(
36903696
$finalScope,
36913697
$ternaryCondResult->hasYield(),
3698+
false,
36923699
$throwPoints,
36933700
$impurePoints,
36943701
static fn (): MutatingScope => $finalScope->filterByTruthyValue($expr),
@@ -4018,11 +4025,11 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
40184025
return new ExpressionResult(
40194026
$scope,
40204027
$hasYield,
4028+
$isAlwaysTerminating,
40214029
$throwPoints,
40224030
$impurePoints,
40234031
static fn (): MutatingScope => $scope->filterByTruthyValue($expr),
40244032
static fn (): MutatingScope => $scope->filterByFalseyValue($expr),
4025-
$isAlwaysTerminating,
40264033
);
40274034
}
40284035

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

4742-
return new ExpressionResult($scope, false, $exprResult->getThrowPoints(), $exprResult->getImpurePoints());
4749+
return new ExpressionResult($scope, false, false, $exprResult->getThrowPoints(), $exprResult->getImpurePoints());
47434750
}
47444751

47454752
/**
@@ -5261,7 +5268,7 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
52615268
$nodeCallback($node, $scope);
52625269
},
52635270
$context,
5264-
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, [], []),
5271+
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, false, [], []),
52655272
true,
52665273
);
52675274
$scope = $result->getScope();
@@ -5294,7 +5301,7 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
52945301
}
52955302
}
52965303

5297-
return new ExpressionResult($scope, $hasYield, $throwPoints, $impurePoints, isAlwaysTerminating: $isAlwaysTerminating);
5304+
return new ExpressionResult($scope, $hasYield, $isAlwaysTerminating, $throwPoints, $impurePoints);
52985305
}
52995306

53005307
/**
@@ -5853,7 +5860,7 @@ static function (): void {
58535860
new GetOffsetValueTypeExpr($assignedExpr, $dimExpr),
58545861
$nodeCallback,
58555862
$context,
5856-
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, [], []),
5863+
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, false, [], []),
58575864
$enterExpressionAssign,
58585865
);
58595866
$scope = $result->getScope();
@@ -5939,7 +5946,7 @@ static function (): void {
59395946
}
59405947
}
59415948

5942-
return new ExpressionResult($scope, $hasYield, $throwPoints, $impurePoints, isAlwaysTerminating: $isAlwaysTerminating);
5949+
return new ExpressionResult($scope, $hasYield, $isAlwaysTerminating, $throwPoints, $impurePoints);
59435950
}
59445951

59455952
/**
@@ -6249,7 +6256,7 @@ private function enterForeach(MutatingScope $scope, MutatingScope $originalScope
62496256
static function (): void {
62506257
},
62516258
ExpressionContext::createDeep(),
6252-
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, [], []),
6259+
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, false, [], []),
62536260
true,
62546261
)->getScope();
62556262
$vars = $this->getAssignedVariables($stmt->valueVar);
@@ -6267,7 +6274,7 @@ static function (): void {
62676274
static function (): void {
62686275
},
62696276
ExpressionContext::createDeep(),
6270-
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, [], []),
6277+
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, false, [], []),
62716278
true,
62726279
)->getScope();
62736280
$vars = array_merge($vars, $this->getAssignedVariables($stmt->keyVar));

0 commit comments

Comments
 (0)