Skip to content

Commit 243d098

Browse files
committed
Refactor enterRightSideAssign to only use Expr, not Type
1 parent 7e742a0 commit 243d098

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

src/Analyser/ExpressionContext.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,27 @@
22

33
namespace PHPStan\Analyser;
44

5-
use PHPStan\Type\Type;
5+
use PhpParser\Node\Expr;
66

77
final class ExpressionContext
88
{
99

1010
private function __construct(
1111
private bool $isDeep,
1212
private ?string $inAssignRightSideVariableName,
13-
private ?Type $inAssignRightSideType,
14-
private ?Type $inAssignRightSideNativeType,
13+
private ?Expr $inAssignRightSideExpr,
1514
)
1615
{
1716
}
1817

1918
public static function createTopLevel(): self
2019
{
21-
return new self(false, null, null, null);
20+
return new self(false, null, null);
2221
}
2322

2423
public static function createDeep(): self
2524
{
26-
return new self(true, null, null, null);
25+
return new self(true, null, null);
2726
}
2827

2928
public function enterDeep(): self
@@ -32,32 +31,27 @@ public function enterDeep(): self
3231
return $this;
3332
}
3433

35-
return new self(true, $this->inAssignRightSideVariableName, $this->inAssignRightSideType, $this->inAssignRightSideNativeType);
34+
return new self(true, $this->inAssignRightSideVariableName, $this->inAssignRightSideExpr);
3635
}
3736

3837
public function isDeep(): bool
3938
{
4039
return $this->isDeep;
4140
}
4241

43-
public function enterRightSideAssign(string $variableName, Type $type, Type $nativeType): self
42+
public function enterRightSideAssign(string $variableName, Expr $expr): self
4443
{
45-
return new self($this->isDeep, $variableName, $type, $nativeType);
44+
return new self($this->isDeep, $variableName, $expr);
4645
}
4746

4847
public function getInAssignRightSideVariableName(): ?string
4948
{
5049
return $this->inAssignRightSideVariableName;
5150
}
5251

53-
public function getInAssignRightSideType(): ?Type
52+
public function getInAssignRightSideExpr(): ?Expr
5453
{
55-
return $this->inAssignRightSideType;
56-
}
57-
58-
public function getInAssignRightSideNativeType(): ?Type
59-
{
60-
return $this->inAssignRightSideNativeType;
54+
return $this->inAssignRightSideExpr;
6155
}
6256

6357
}

src/Analyser/NodeScopeResolver.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2582,8 +2582,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context): Exp
25822582
if ($expr->var instanceof Variable && is_string($expr->var->name)) {
25832583
$context = $context->enterRightSideAssign(
25842584
$expr->var->name,
2585-
$scope->getType($expr->expr),
2586-
$scope->getNativeType($expr->expr),
2585+
$expr->expr,
25872586
);
25882587
}
25892588

@@ -4828,13 +4827,12 @@ private function processClosureNode(
48284827
$useScope = $useScope->enterExpressionAssign($use->var);
48294828

48304829
$inAssignRightSideVariableName = $context->getInAssignRightSideVariableName();
4831-
$inAssignRightSideType = $context->getInAssignRightSideType();
4832-
$inAssignRightSideNativeType = $context->getInAssignRightSideNativeType();
4830+
$inAssignRightSideExpr = $context->getInAssignRightSideExpr();
48334831
if (
48344832
$inAssignRightSideVariableName === $use->var->name
4835-
&& $inAssignRightSideType !== null
4836-
&& $inAssignRightSideNativeType !== null
4833+
&& $inAssignRightSideExpr !== null
48374834
) {
4835+
$inAssignRightSideType = $scope->getType($inAssignRightSideExpr);
48384836
if ($inAssignRightSideType instanceof ClosureType) {
48394837
$variableType = $inAssignRightSideType;
48404838
} else {
@@ -4845,6 +4843,7 @@ private function processClosureNode(
48454843
$variableType = TypeCombinator::union($scope->getVariableType($inAssignRightSideVariableName), $inAssignRightSideType);
48464844
}
48474845
}
4846+
$inAssignRightSideNativeType = $scope->getNativeType($inAssignRightSideExpr);
48484847
if ($inAssignRightSideNativeType instanceof ClosureType) {
48494848
$variableNativeType = $inAssignRightSideNativeType;
48504849
} else {

0 commit comments

Comments
 (0)