Skip to content

Commit 7a35388

Browse files
committed
Nuke OriginalPropertyTypeExpr
1 parent c586014 commit 7a35388

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
@@ -34,7 +34,6 @@
3434
use PHPStan\Node\Expr\GetIterableKeyTypeExpr;
3535
use PHPStan\Node\Expr\GetIterableValueTypeExpr;
3636
use PHPStan\Node\Expr\GetOffsetValueTypeExpr;
37-
use PHPStan\Node\Expr\OriginalPropertyTypeExpr;
3837
use PHPStan\Node\Expr\ParameterVariableOriginalValueExpr;
3938
use PHPStan\Node\Expr\PropertyInitializationExpr;
4039
use PHPStan\Node\Expr\SetExistingOffsetValueTypeExpr;
@@ -689,15 +688,6 @@ public function getType(Expr $node): Type
689688
return $node->getExprType();
690689
}
691690

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

703693
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
@@ -84,7 +84,6 @@
8484
use PHPStan\Node\Expr\GetIterableKeyTypeExpr;
8585
use PHPStan\Node\Expr\GetIterableValueTypeExpr;
8686
use PHPStan\Node\Expr\GetOffsetValueTypeExpr;
87-
use PHPStan\Node\Expr\OriginalPropertyTypeExpr;
8887
use PHPStan\Node\Expr\PropertyInitializationExpr;
8988
use PHPStan\Node\Expr\SetExistingOffsetValueTypeExpr;
9089
use PHPStan\Node\Expr\SetOffsetValueTypeExpr;
@@ -5022,12 +5021,8 @@ private function processAssignVar(
50225021
$originalVar = $var;
50235022
$assignedPropertyExpr = $assignedExpr;
50245023
while ($var instanceof ArrayDimFetch) {
5025-
$varForSetOffsetValue = $var->var;
5026-
if ($varForSetOffsetValue instanceof PropertyFetch || $varForSetOffsetValue instanceof StaticPropertyFetch) {
5027-
$varForSetOffsetValue = new OriginalPropertyTypeExpr($varForSetOffsetValue);
5028-
}
50295024
$assignedPropertyExpr = new SetOffsetValueTypeExpr(
5030-
$varForSetOffsetValue,
5025+
$var->var,
50315026
$var->dim,
50325027
$assignedPropertyExpr,
50335028
);
@@ -5342,12 +5337,8 @@ static function (): void {
53425337
$dimFetchStack = [];
53435338
$assignedPropertyExpr = $assignedExpr;
53445339
while ($var instanceof ExistingArrayDimFetch) {
5345-
$varForSetOffsetValue = $var->getVar();
5346-
if ($varForSetOffsetValue instanceof PropertyFetch || $varForSetOffsetValue instanceof StaticPropertyFetch) {
5347-
$varForSetOffsetValue = new OriginalPropertyTypeExpr($varForSetOffsetValue);
5348-
}
53495340
$assignedPropertyExpr = new SetExistingOffsetValueTypeExpr(
5350-
$varForSetOffsetValue,
5341+
$var->getVar(),
53515342
$var->getDim(),
53525343
$assignedPropertyExpr,
53535344
);

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;
@@ -57,11 +56,6 @@ protected function pPHPStan_Node_ExistingArrayDimFetch(ExistingArrayDimFetch $ex
5756
return sprintf('__phpstanExistingArrayDimFetch(%s, %s)', $this->p($expr->getVar()), $this->p($expr->getDim()));
5857
}
5958

60-
protected function pPHPStan_Node_OriginalPropertyTypeExpr(OriginalPropertyTypeExpr $expr): string // phpcs:ignore
61-
{
62-
return sprintf('__phpstanOriginalPropertyType(%s)', $this->p($expr->getPropertyFetch()));
63-
}
64-
6559
protected function pPHPStan_Node_SetOffsetValueTypeExpr(SetOffsetValueTypeExpr $expr): string // phpcs:ignore
6660
{
6761
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->acceptsWithReason($propertyType, $assignedValueType, $scope->isDeclareStrictTypes());
6777
if (!$accepts->result) {

0 commit comments

Comments
 (0)