Skip to content

Commit ed4f0c2

Browse files
authored
Merge branch refs/heads/2.1.x into 2.2.x
2 parents c480f25 + c646e17 commit ed4f0c2

File tree

3 files changed

+59
-13
lines changed

3 files changed

+59
-13
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Analyser\ExprHandler\Virtual;
4+
5+
use PhpParser\Node\Expr;
6+
use PhpParser\Node\Stmt;
7+
use PHPStan\Analyser\ExpressionContext;
8+
use PHPStan\Analyser\ExpressionResult;
9+
use PHPStan\Analyser\ExpressionResultStorage;
10+
use PHPStan\Analyser\ExprHandler;
11+
use PHPStan\Analyser\MutatingScope;
12+
use PHPStan\Analyser\NodeScopeResolver;
13+
use PHPStan\DependencyInjection\AutowiredService;
14+
use PHPStan\Node\Expr\AlwaysRememberedExpr;
15+
use PHPStan\Type\Type;
16+
17+
/**
18+
* @implements ExprHandler<AlwaysRememberedExpr>
19+
*/
20+
#[AutowiredService]
21+
final class AlwaysRememberedExprHandler implements ExprHandler
22+
{
23+
24+
public function supports(Expr $expr): bool
25+
{
26+
return $expr instanceof AlwaysRememberedExpr;
27+
}
28+
29+
public function processExpr(
30+
NodeScopeResolver $nodeScopeResolver,
31+
Stmt $stmt,
32+
Expr $expr,
33+
MutatingScope $scope,
34+
ExpressionResultStorage $storage,
35+
callable $nodeCallback,
36+
ExpressionContext $context,
37+
): ExpressionResult
38+
{
39+
$innerExpr = $expr->getExpr();
40+
$result = $nodeScopeResolver->processExprNode($stmt, $innerExpr, $scope, $storage, $nodeCallback, $context);
41+
$scope = $result->getScope();
42+
43+
return new ExpressionResult(
44+
$scope,
45+
hasYield: $result->hasYield(),
46+
isAlwaysTerminating: $result->isAlwaysTerminating(),
47+
throwPoints: $result->getThrowPoints(),
48+
impurePoints: $result->getImpurePoints(),
49+
truthyScopeCallback: static fn (): MutatingScope => $scope->filterByTruthyValue($innerExpr),
50+
falseyScopeCallback: static fn (): MutatingScope => $scope->filterByFalseyValue($innerExpr),
51+
);
52+
}
53+
54+
public function resolveType(MutatingScope $scope, Expr $expr): Type
55+
{
56+
return $scope->nativeTypesPromoted ? $expr->getNativeExprType() : $expr->getExprType();
57+
}
58+
59+
}

src/Analyser/MutatingScope.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,10 +1055,6 @@ private function resolveType(string $exprString, Expr $node): Type
10551055
return $exprHandler->resolveType($this, $node);
10561056
}
10571057

1058-
if ($node instanceof AlwaysRememberedExpr) {
1059-
return $this->nativeTypesPromoted ? $node->getNativeExprType() : $node->getExprType();
1060-
}
1061-
10621058
return new MixedType();
10631059
}
10641060

src/Analyser/NodeScopeResolver.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
use PHPStan\Node\DeepNodeCloner;
7474
use PHPStan\Node\DoWhileLoopConditionNode;
7575
use PHPStan\Node\ExecutionEndNode;
76-
use PHPStan\Node\Expr\AlwaysRememberedExpr;
7776
use PHPStan\Node\Expr\ExistingArrayDimFetch;
7877
use PHPStan\Node\Expr\ForeachValueByRefExpr;
7978
use PHPStan\Node\Expr\GetIterableKeyTypeExpr;
@@ -2511,14 +2510,6 @@ public function processExprNode(
25112510
if ($expr instanceof List_) {
25122511
// only in assign and foreach, processed elsewhere
25132512
return new ExpressionResult($scope, hasYield: false, isAlwaysTerminating: false, throwPoints: [], impurePoints: []);
2514-
} elseif ($expr instanceof AlwaysRememberedExpr) {
2515-
$result = $this->processExprNode($stmt, $expr->getExpr(), $scope, $storage, $nodeCallback, $context);
2516-
$hasYield = $result->hasYield();
2517-
$throwPoints = $result->getThrowPoints();
2518-
$impurePoints = $result->getImpurePoints();
2519-
$isAlwaysTerminating = $result->isAlwaysTerminating();
2520-
$scope = $result->getScope();
2521-
$expr = $expr->getExpr();
25222513
} elseif ($expr instanceof FunctionCallableNode) {
25232514
$throwPoints = [];
25242515
$impurePoints = [];

0 commit comments

Comments
 (0)