Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ExpressionResult isAlwaysTerminating is consistent with StatementResult
  • Loading branch information
staabm committed Jul 21, 2025
commit 95bb39d51e53f9a50e3c84747ed89a5455d3c6af
2 changes: 1 addition & 1 deletion src/Analyser/ExpressionResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ final class ExpressionResult
public function __construct(
private MutatingScope $scope,
private bool $hasYield,
private bool $isAlwaysTerminating,
private array $throwPoints,
private array $impurePoints,
?callable $truthyScopeCallback = null,
?callable $falseyScopeCallback = null,
private bool $isAlwaysTerminating = false,
)
{
$this->truthyScopeCallback = $truthyScopeCallback;
Expand Down
33 changes: 20 additions & 13 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1915,7 +1915,7 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
$nodeCallback($node, $scope);
},
ExpressionContext::createDeep(),
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, [], []),
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, false, [], []),
false,
)->getScope();
} elseif ($var instanceof PropertyFetch) {
Expand Down Expand Up @@ -2475,7 +2475,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context): Exp
$scope = $scope->exitExpressionAssign($expr->expr);
}

return new ExpressionResult($scope, $hasYield, $throwPoints, $impurePoints, isAlwaysTerminating: $isAlwaysTerminating);
return new ExpressionResult($scope, $hasYield, $isAlwaysTerminating, $throwPoints, $impurePoints);
},
true,
);
Expand Down Expand Up @@ -2513,9 +2513,9 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context): Exp
return new ExpressionResult(
$result->getScope()->mergeWith($originalScope),
$result->hasYield(),
$result->isAlwaysTerminating(),
$result->getThrowPoints(),
$result->getImpurePoints(),
isAlwaysTerminating: $result->isAlwaysTerminating(),
);
}

Expand Down Expand Up @@ -2933,6 +2933,7 @@ static function (): void {
return new ExpressionResult(
$scope,
$exprResult->hasYield(),
false,
$exprResult->getThrowPoints(),
$exprResult->getImpurePoints(),
static fn (): MutatingScope => $scope->filterByTruthyValue($expr),
Expand Down Expand Up @@ -3135,6 +3136,7 @@ static function (): void {
return new ExpressionResult(
$scope,
$exprResult->hasYield(),
false,
$exprResult->getThrowPoints(),
$exprResult->getImpurePoints(),
static fn (): MutatingScope => $scope->filterByTruthyValue($expr),
Expand Down Expand Up @@ -3172,6 +3174,7 @@ static function (): void {
return new ExpressionResult(
$processClosureResult->getScope(),
false,
false,
[],
[],
);
Expand All @@ -3180,6 +3183,7 @@ static function (): void {
return new ExpressionResult(
$result->getScope(),
$result->hasYield(),
false,
[],
[],
);
Expand Down Expand Up @@ -3276,6 +3280,7 @@ static function (): void {
return new ExpressionResult(
$leftMergedWithRightScope,
$leftResult->hasYield() || $rightResult->hasYield(),
false,
array_merge($leftResult->getThrowPoints(), $rightResult->getThrowPoints()),
array_merge($leftResult->getImpurePoints(), $rightResult->getImpurePoints()),
static fn (): MutatingScope => $rightResult->getScope()->filterByTruthyValue($expr),
Expand All @@ -3296,6 +3301,7 @@ static function (): void {
return new ExpressionResult(
$leftMergedWithRightScope,
$leftResult->hasYield() || $rightResult->hasYield(),
false,
array_merge($leftResult->getThrowPoints(), $rightResult->getThrowPoints()),
array_merge($leftResult->getImpurePoints(), $rightResult->getImpurePoints()),
static fn (): MutatingScope => $leftMergedWithRightScope->filterByTruthyValue($expr),
Expand Down Expand Up @@ -3494,7 +3500,7 @@ static function (): void {
}
} elseif ($expr instanceof List_) {
// only in assign and foreach, processed elsewhere
return new ExpressionResult($scope, false, [], []);
return new ExpressionResult($scope, false, false, [], []);
} elseif ($expr instanceof New_) {
$parametersAcceptor = null;
$constructorReflection = null;
Expand Down Expand Up @@ -3646,7 +3652,7 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
$nodeCallback($node, $scope);
},
$context,
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, [], []),
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, false, [], []),
false,
)->getScope();
} elseif ($expr instanceof Ternary) {
Expand Down Expand Up @@ -3691,6 +3697,7 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
return new ExpressionResult(
$finalScope,
$ternaryCondResult->hasYield(),
false,
$throwPoints,
$impurePoints,
static fn (): MutatingScope => $finalScope->filterByTruthyValue($expr),
Expand Down Expand Up @@ -4020,11 +4027,11 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
return new ExpressionResult(
$scope,
$hasYield,
$isAlwaysTerminating,
$throwPoints,
$impurePoints,
static fn (): MutatingScope => $scope->filterByTruthyValue($expr),
static fn (): MutatingScope => $scope->filterByFalseyValue($expr),
$isAlwaysTerminating,
);
}

Expand Down Expand Up @@ -4741,7 +4748,7 @@ private function processArrowFunctionNode(
$nodeCallback(new InArrowFunctionNode($arrowFunctionType, $expr), $arrowFunctionScope);
$exprResult = $this->processExprNode($stmt, $expr->expr, $arrowFunctionScope, $nodeCallback, ExpressionContext::createTopLevel());

return new ExpressionResult($scope, false, $exprResult->getThrowPoints(), $exprResult->getImpurePoints());
return new ExpressionResult($scope, false, false, $exprResult->getThrowPoints(), $exprResult->getImpurePoints());
}

/**
Expand Down Expand Up @@ -5263,7 +5270,7 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
$nodeCallback($node, $scope);
},
$context,
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, [], []),
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, false, [], []),
true,
);
$scope = $result->getScope();
Expand Down Expand Up @@ -5296,7 +5303,7 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
}
}

return new ExpressionResult($scope, $hasYield, $throwPoints, $impurePoints, isAlwaysTerminating: $isAlwaysTerminating);
return new ExpressionResult($scope, $hasYield, $isAlwaysTerminating, $throwPoints, $impurePoints);
}

/**
Expand Down Expand Up @@ -5855,7 +5862,7 @@ static function (): void {
new GetOffsetValueTypeExpr($assignedExpr, $dimExpr),
$nodeCallback,
$context,
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, [], []),
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, false, [], []),
$enterExpressionAssign,
);
$scope = $result->getScope();
Expand Down Expand Up @@ -5941,7 +5948,7 @@ static function (): void {
}
}

return new ExpressionResult($scope, $hasYield, $throwPoints, $impurePoints, isAlwaysTerminating: $isAlwaysTerminating);
return new ExpressionResult($scope, $hasYield, $isAlwaysTerminating, $throwPoints, $impurePoints);
}

/**
Expand Down Expand Up @@ -6277,7 +6284,7 @@ private function enterForeach(MutatingScope $scope, MutatingScope $originalScope
static function (): void {
},
ExpressionContext::createDeep(),
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, [], []),
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, false, [], []),
true,
)->getScope();
$vars = $this->getAssignedVariables($stmt->valueVar);
Expand All @@ -6295,7 +6302,7 @@ static function (): void {
static function (): void {
},
ExpressionContext::createDeep(),
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, [], []),
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, false, [], []),
true,
)->getScope();
$vars = array_merge($vars, $this->getAssignedVariables($stmt->keyVar));
Expand Down