@@ -5627,8 +5627,8 @@ static function (): void {
5627
5627
$ assignedExprType = $ scope ->getType ($ assignedExpr );
5628
5628
$ nodeCallback (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scope );
5629
5629
if ($ propertyReflection ->canChangeTypeAfterAssignment ()) {
5630
+ $ assignedNativeType = $ scope ->getNativeType ($ assignedExpr );
5630
5631
if ($ propertyReflection ->hasNativeType ()) {
5631
- $ assignedNativeType = $ scope ->getNativeType ($ assignedExpr );
5632
5632
$ propertyNativeType = $ propertyReflection ->getNativeType ();
5633
5633
5634
5634
$ assignedTypeIsCompatible = false ;
@@ -5648,10 +5648,14 @@ static function (): void {
5648
5648
TypeCombinator::intersect ($ assignedNativeType ->toCoercedArgumentType (true ), $ propertyNativeType ),
5649
5649
);
5650
5650
} 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
+ );
5652
5656
}
5653
5657
} else {
5654
- $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ scope -> getNativeType ( $ assignedExpr ) );
5658
+ $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ assignedNativeType );
5655
5659
}
5656
5660
}
5657
5661
$ declaringClass = $ propertyReflection ->getDeclaringClass ();
@@ -5717,8 +5721,8 @@ static function (): void {
5717
5721
$ assignedExprType = $ scope ->getType ($ assignedExpr );
5718
5722
$ nodeCallback (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scope );
5719
5723
if ($ propertyReflection !== null && $ propertyReflection ->canChangeTypeAfterAssignment ()) {
5724
+ $ assignedNativeType = $ scope ->getNativeType ($ assignedExpr );
5720
5725
if ($ propertyReflection ->hasNativeType ()) {
5721
- $ assignedNativeType = $ scope ->getNativeType ($ assignedExpr );
5722
5726
$ propertyNativeType = $ propertyReflection ->getNativeType ();
5723
5727
5724
5728
$ assignedTypeIsCompatible = false ;
@@ -5738,10 +5742,14 @@ static function (): void {
5738
5742
TypeCombinator::intersect ($ assignedNativeType ->toCoercedArgumentType (true ), $ propertyNativeType ),
5739
5743
);
5740
5744
} 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
+ );
5742
5750
}
5743
5751
} else {
5744
- $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ scope -> getNativeType ( $ assignedExpr ) );
5752
+ $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ assignedNativeType );
5745
5753
}
5746
5754
}
5747
5755
} else {
0 commit comments