Skip to content

Commit 4592941

Browse files
committed
Nuke OriginalPropertyTypeExpr
1 parent 97ba50a commit 4592941

File tree

5 files changed

+13
-62
lines changed

5 files changed

+13
-62
lines changed

src/Analyser/MutatingScope.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
use PHPStan\Node\Expr\GetIterableKeyTypeExpr;
3333
use PHPStan\Node\Expr\GetIterableValueTypeExpr;
3434
use PHPStan\Node\Expr\GetOffsetValueTypeExpr;
35-
use PHPStan\Node\Expr\OriginalPropertyTypeExpr;
3635
use PHPStan\Node\Expr\ParameterVariableOriginalValueExpr;
3736
use PHPStan\Node\Expr\PropertyInitializationExpr;
3837
use PHPStan\Node\Expr\SetExistingOffsetValueTypeExpr;
@@ -690,15 +689,6 @@ public function getType(Expr $node): Type
690689
return $node->getExprType();
691690
}
692691

693-
if ($node instanceof OriginalPropertyTypeExpr) {
694-
$propertyReflection = $this->propertyReflectionFinder->findPropertyReflectionFromNode($node->getPropertyFetch(), $this);
695-
if ($propertyReflection === null) {
696-
return new ErrorType();
697-
}
698-
699-
return $propertyReflection->getReadableType();
700-
}
701-
702692
$key = $this->getNodeKey($node);
703693

704694
if (!array_key_exists($key, $this->resolvedTypes)) {

src/Analyser/NodeScopeResolver.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
use PHPStan\Node\Expr\GetIterableKeyTypeExpr;
8484
use PHPStan\Node\Expr\GetIterableValueTypeExpr;
8585
use PHPStan\Node\Expr\GetOffsetValueTypeExpr;
86-
use PHPStan\Node\Expr\OriginalPropertyTypeExpr;
8786
use PHPStan\Node\Expr\PropertyInitializationExpr;
8887
use PHPStan\Node\Expr\SetExistingOffsetValueTypeExpr;
8988
use PHPStan\Node\Expr\SetOffsetValueTypeExpr;
@@ -5016,12 +5015,8 @@ private function processAssignVar(
50165015
$originalVar = $var;
50175016
$assignedPropertyExpr = $assignedExpr;
50185017
while ($var instanceof ArrayDimFetch) {
5019-
$varForSetOffsetValue = $var->var;
5020-
if ($varForSetOffsetValue instanceof PropertyFetch || $varForSetOffsetValue instanceof StaticPropertyFetch) {
5021-
$varForSetOffsetValue = new OriginalPropertyTypeExpr($varForSetOffsetValue);
5022-
}
50235018
$assignedPropertyExpr = new SetOffsetValueTypeExpr(
5024-
$varForSetOffsetValue,
5019+
$var->var,
50255020
$var->dim,
50265021
$assignedPropertyExpr,
50275022
);
@@ -5336,12 +5331,8 @@ static function (): void {
53365331
$dimFetchStack = [];
53375332
$assignedPropertyExpr = $assignedExpr;
53385333
while ($var instanceof ExistingArrayDimFetch) {
5339-
$varForSetOffsetValue = $var->getVar();
5340-
if ($varForSetOffsetValue instanceof PropertyFetch || $varForSetOffsetValue instanceof StaticPropertyFetch) {
5341-
$varForSetOffsetValue = new OriginalPropertyTypeExpr($varForSetOffsetValue);
5342-
}
53435334
$assignedPropertyExpr = new SetExistingOffsetValueTypeExpr(
5344-
$varForSetOffsetValue,
5335+
$var->getVar(),
53455336
$var->getDim(),
53465337
$assignedPropertyExpr,
53475338
);

src/Node/Expr/OriginalPropertyTypeExpr.php

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/Node/Printer/Printer.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use PHPStan\Node\Expr\GetIterableKeyTypeExpr;
99
use PHPStan\Node\Expr\GetIterableValueTypeExpr;
1010
use PHPStan\Node\Expr\GetOffsetValueTypeExpr;
11-
use PHPStan\Node\Expr\OriginalPropertyTypeExpr;
1211
use PHPStan\Node\Expr\ParameterVariableOriginalValueExpr;
1312
use PHPStan\Node\Expr\PropertyInitializationExpr;
1413
use PHPStan\Node\Expr\SetExistingOffsetValueTypeExpr;
@@ -55,11 +54,6 @@ protected function pPHPStan_Node_ExistingArrayDimFetch(ExistingArrayDimFetch $ex
5554
return sprintf('__phpstanExistingArrayDimFetch(%s, %s)', $this->p($expr->getVar()), $this->p($expr->getDim()));
5655
}
5756

58-
protected function pPHPStan_Node_OriginalPropertyTypeExpr(OriginalPropertyTypeExpr $expr): string // phpcs:ignore
59-
{
60-
return sprintf('__phpstanOriginalPropertyType(%s)', $this->p($expr->getPropertyFetch()));
61-
}
62-
6357
protected function pPHPStan_Node_SetOffsetValueTypeExpr(SetOffsetValueTypeExpr $expr): string // phpcs:ignore
6458
{
6559
return sprintf('__phpstanSetOffsetValueType(%s, %s, %s)', $this->p($expr->getVar()), $expr->getDim() !== null ? $this->p($expr->getDim()) : 'null', $this->p($expr->getValue()));

src/Rules/Properties/TypesAssignedToPropertiesRule.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PhpParser\Node;
66
use PHPStan\Analyser\Scope;
7+
use PHPStan\Node\Expr\SetOffsetValueTypeExpr;
78
use PHPStan\Node\PropertyAssignNode;
89
use PHPStan\Reflection\PropertyReflection;
910
use PHPStan\Rules\IdentifierRuleError;
@@ -61,7 +62,16 @@ private function processSingleProperty(
6162

6263
$propertyType = $propertyReflection->getWritableType();
6364
$scope = $propertyReflection->getScope();
64-
$assignedValueType = $scope->getType($assignedExpr);
65+
66+
if ($assignedExpr instanceof SetOffsetValueTypeExpr) {
67+
// TODO: Document why we need this only for setting offset values, do we actually need this?! xD
68+
$assignedValueType = $propertyType->setOffsetValueType(
69+
$assignedExpr->getDim() !== null ? $scope->getType($assignedExpr->getDim()) : null,
70+
$scope->getType($assignedExpr->getValue()),
71+
);
72+
} else {
73+
$assignedValueType = $scope->getType($assignedExpr);
74+
}
6575

6676
$accepts = $this->ruleLevelHelper->accepts($propertyType, $assignedValueType, $scope->isDeclareStrictTypes());
6777
if (!$accepts->result) {

0 commit comments

Comments
 (0)