@@ -5556,7 +5556,18 @@ static function (): void {
55565556 $ assignedExprType = $ scope ->getType ($ assignedExpr );
55575557 $ nodeCallback (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scope );
55585558 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+ }
55605571 }
55615572 $ declaringClass = $ propertyReflection ->getDeclaringClass ();
55625573 if ($ declaringClass ->hasNativeProperty ($ propertyName )) {
@@ -5621,7 +5632,18 @@ static function (): void {
56215632 $ assignedExprType = $ scope ->getType ($ assignedExpr );
56225633 $ nodeCallback (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scope );
56235634 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+ }
56255647 }
56265648 } else {
56275649 // fallback
0 commit comments