@@ -5556,7 +5556,18 @@ static function (): void {
5556
5556
$ assignedExprType = $ scope ->getType ($ assignedExpr );
5557
5557
$ nodeCallback (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scope );
5558
5558
if ($ propertyReflection ->canChangeTypeAfterAssignment ()) {
5559
- $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ scope ->getNativeType ($ assignedExpr ));
5559
+ if ($ propertyReflection ->hasNativeType ()) {
5560
+ $ propertyNativeType = $ propertyReflection ->getNativeType ();
5561
+ if ($ propertyNativeType ->isSuperTypeOf ($ assignedExprType )->yes ()) {
5562
+ $ assignedExprNativeType = $ scope ->getNativeType ($ assignedExpr );
5563
+ if (!$ propertyNativeType ->isSuperTypeOf ($ assignedExprNativeType )->yes ()) {
5564
+ $ assignedExprNativeType = $ propertyNativeType ;
5565
+ }
5566
+ $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ assignedExprNativeType );
5567
+ }
5568
+ } else {
5569
+ $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ scope ->getNativeType ($ assignedExpr ));
5570
+ }
5560
5571
}
5561
5572
$ declaringClass = $ propertyReflection ->getDeclaringClass ();
5562
5573
if ($ declaringClass ->hasNativeProperty ($ propertyName )) {
@@ -5621,7 +5632,18 @@ static function (): void {
5621
5632
$ assignedExprType = $ scope ->getType ($ assignedExpr );
5622
5633
$ nodeCallback (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scope );
5623
5634
if ($ propertyReflection !== null && $ propertyReflection ->canChangeTypeAfterAssignment ()) {
5624
- $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ scope ->getNativeType ($ assignedExpr ));
5635
+ if ($ propertyReflection ->hasNativeType ()) {
5636
+ $ propertyNativeType = $ propertyReflection ->getNativeType ();
5637
+ if ($ propertyNativeType ->isSuperTypeOf ($ assignedExprType )->yes ()) {
5638
+ $ assignedExprNativeType = $ scope ->getNativeType ($ assignedExpr );
5639
+ if (!$ propertyNativeType ->isSuperTypeOf ($ assignedExprNativeType )->yes ()) {
5640
+ $ assignedExprNativeType = $ propertyNativeType ;
5641
+ }
5642
+ $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ assignedExprNativeType );
5643
+ }
5644
+ } else {
5645
+ $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ scope ->getNativeType ($ assignedExpr ));
5646
+ }
5625
5647
}
5626
5648
} else {
5627
5649
// fallback
0 commit comments