Skip to content

Commit aa441ff

Browse files
committed
fix
1 parent c6c03e6 commit aa441ff

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5626,9 +5626,20 @@ static function (): void {
56265626
$nodeCallback(new PropertyAssignNode($var, $assignedExpr, $isAssignOp), $scope);
56275627
if ($propertyReflection->canChangeTypeAfterAssignment()) {
56285628
if ($propertyReflection->hasNativeType() && $scope->isDeclareStrictTypes()) {
5629+
$assignedNativeType = $scope->getNativeType($assignedExpr);
56295630
$propertyNativeType = $propertyReflection->getNativeType();
56305631

5631-
$scope = $scope->assignExpression($var, TypeCombinator::intersect($assignedExprType->toCoercedArgumentType(true), $propertyNativeType), TypeCombinator::intersect($scope->getNativeType($assignedExpr)->toCoercedArgumentType(true), $propertyNativeType));
5632+
$newAssignedType = TypeCombinator::intersect($assignedExprType, $propertyNativeType);
5633+
if ($newAssignedType instanceof NeverType) {
5634+
$newAssignedType = TypeCombinator::intersect($assignedExprType->toCoercedArgumentType(true), $propertyNativeType);
5635+
}
5636+
5637+
$newAssignedNativeType = TypeCombinator::intersect($assignedNativeType, $propertyNativeType);
5638+
if ($newAssignedNativeType instanceof NeverType) {
5639+
$newAssignedNativeType = TypeCombinator::intersect($assignedNativeType->toCoercedArgumentType(true), $propertyNativeType);
5640+
}
5641+
5642+
$scope = $scope->assignExpression($var, $newAssignedType, $newAssignedNativeType);
56325643
} else {
56335644
$scope = $scope->assignExpression($var, $assignedExprType, $scope->getNativeType($assignedExpr));
56345645
}
@@ -5697,9 +5708,20 @@ static function (): void {
56975708
$nodeCallback(new PropertyAssignNode($var, $assignedExpr, $isAssignOp), $scope);
56985709
if ($propertyReflection !== null && $propertyReflection->canChangeTypeAfterAssignment()) {
56995710
if ($propertyReflection->hasNativeType() && $scope->isDeclareStrictTypes()) {
5711+
$assignedNativeType = $scope->getNativeType($assignedExpr);
57005712
$propertyNativeType = $propertyReflection->getNativeType();
57015713

5702-
$scope = $scope->assignExpression($var, TypeCombinator::intersect($assignedExprType->toCoercedArgumentType(true), $propertyNativeType), TypeCombinator::intersect($scope->getNativeType($assignedExpr)->toCoercedArgumentType(true), $propertyNativeType));
5714+
$newAssignedType = TypeCombinator::intersect($assignedExprType, $propertyNativeType);
5715+
if ($newAssignedType instanceof NeverType) {
5716+
$newAssignedType = TypeCombinator::intersect($assignedExprType->toCoercedArgumentType(true), $propertyNativeType);
5717+
}
5718+
5719+
$newAssignedNativeType = TypeCombinator::intersect($assignedNativeType, $propertyNativeType);
5720+
if ($newAssignedNativeType instanceof NeverType) {
5721+
$newAssignedNativeType = TypeCombinator::intersect($assignedNativeType->toCoercedArgumentType(true), $propertyNativeType);
5722+
}
5723+
5724+
$scope = $scope->assignExpression($var, $newAssignedType, $newAssignedNativeType);
57035725
} else {
57045726
$scope = $scope->assignExpression($var, $assignedExprType, $scope->getNativeType($assignedExpr));
57055727
}

0 commit comments

Comments
 (0)