Skip to content

Commit f66ec0c

Browse files
committed
cleanup
1 parent 3adf2d9 commit f66ec0c

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/Analyser/NodeScopeResolver.php

+14-6
Original file line numberDiff line numberDiff line change
@@ -5627,8 +5627,8 @@ static function (): void {
56275627
$assignedExprType = $scope->getType($assignedExpr);
56285628
$nodeCallback(new PropertyAssignNode($var, $assignedExpr, $isAssignOp), $scope);
56295629
if ($propertyReflection->canChangeTypeAfterAssignment()) {
5630+
$assignedNativeType = $scope->getNativeType($assignedExpr);
56305631
if ($propertyReflection->hasNativeType()) {
5631-
$assignedNativeType = $scope->getNativeType($assignedExpr);
56325632
$propertyNativeType = $propertyReflection->getNativeType();
56335633

56345634
$assignedTypeIsCompatible = false;
@@ -5648,10 +5648,14 @@ static function (): void {
56485648
TypeCombinator::intersect($assignedNativeType->toCoercedArgumentType(true), $propertyNativeType),
56495649
);
56505650
} else {
5651-
$scope = $scope->assignExpression($var, $assignedExprType, $scope->getNativeType($assignedExpr));
5651+
$scope = $scope->assignExpression(
5652+
$var,
5653+
TypeCombinator::intersect($assignedExprType, $propertyNativeType),
5654+
TypeCombinator::intersect($assignedNativeType, $propertyNativeType),
5655+
);
56525656
}
56535657
} else {
5654-
$scope = $scope->assignExpression($var, $assignedExprType, $scope->getNativeType($assignedExpr));
5658+
$scope = $scope->assignExpression($var, $assignedExprType, $assignedNativeType);
56555659
}
56565660
}
56575661
$declaringClass = $propertyReflection->getDeclaringClass();
@@ -5717,8 +5721,8 @@ static function (): void {
57175721
$assignedExprType = $scope->getType($assignedExpr);
57185722
$nodeCallback(new PropertyAssignNode($var, $assignedExpr, $isAssignOp), $scope);
57195723
if ($propertyReflection !== null && $propertyReflection->canChangeTypeAfterAssignment()) {
5724+
$assignedNativeType = $scope->getNativeType($assignedExpr);
57205725
if ($propertyReflection->hasNativeType()) {
5721-
$assignedNativeType = $scope->getNativeType($assignedExpr);
57225726
$propertyNativeType = $propertyReflection->getNativeType();
57235727

57245728
$assignedTypeIsCompatible = false;
@@ -5738,10 +5742,14 @@ static function (): void {
57385742
TypeCombinator::intersect($assignedNativeType->toCoercedArgumentType(true), $propertyNativeType),
57395743
);
57405744
} else {
5741-
$scope = $scope->assignExpression($var, $assignedExprType, $scope->getNativeType($assignedExpr));
5745+
$scope = $scope->assignExpression(
5746+
$var,
5747+
TypeCombinator::intersect($assignedExprType, $propertyNativeType),
5748+
TypeCombinator::intersect($assignedNativeType, $propertyNativeType),
5749+
);
57425750
}
57435751
} else {
5744-
$scope = $scope->assignExpression($var, $assignedExprType, $scope->getNativeType($assignedExpr));
5752+
$scope = $scope->assignExpression($var, $assignedExprType, $assignedNativeType);
57455753
}
57465754
}
57475755
} else {

0 commit comments

Comments
 (0)