@@ -5628,25 +5628,28 @@ static function (): void {
56285628 $ nodeCallback (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scope );
56295629 if ($ propertyReflection ->canChangeTypeAfterAssignment ()) {
56305630 if ($ propertyReflection ->hasNativeType ()) {
5631- $ assignedNativeType = $ scope ->getNativeType ($ assignedExpr );
56325631 $ propertyNativeType = $ propertyReflection ->getNativeType ();
56335632
5634- $ assignedTypeIsCompatible = false ;
5635- foreach (TypeUtils::flattenTypes ($ propertyNativeType ) as $ type ) {
5636- if ($ type ->isSuperTypeOf ($ assignedNativeType )->yes ()) {
5637- $ assignedTypeIsCompatible = true ;
5638- break ;
5633+ $ assignedTypeIsCompatible = $ propertyNativeType ->isSuperTypeOf ($ assignedExprType )->yes ();
5634+ if (!$ assignedTypeIsCompatible ) {
5635+ foreach (TypeUtils::flattenTypes ($ propertyNativeType ) as $ type ) {
5636+ if ($ type ->isSuperTypeOf ($ assignedExprType )->yes ()) {
5637+ $ assignedTypeIsCompatible = true ;
5638+ break ;
5639+ }
56395640 }
56405641 }
56415642
56425643 if ($ assignedTypeIsCompatible ) {
5643- $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ assignedNativeType );
5644+ $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ scope -> getNativeType ( $ assignedExpr ) );
56445645 } elseif ($ scope ->isDeclareStrictTypes ()) {
56455646 $ scope = $ scope ->assignExpression (
56465647 $ var ,
56475648 TypeCombinator::intersect ($ assignedExprType ->toCoercedArgumentType (true ), $ propertyNativeType ),
5648- TypeCombinator::intersect ($ assignedNativeType ->toCoercedArgumentType (true ), $ propertyNativeType ),
5649+ TypeCombinator::intersect ($ scope -> getNativeType ( $ assignedExpr ) ->toCoercedArgumentType (true ), $ propertyNativeType ),
56495650 );
5651+ } else {
5652+ $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ scope ->getNativeType ($ assignedExpr ));
56505653 }
56515654 } else {
56525655 $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ scope ->getNativeType ($ assignedExpr ));
@@ -5716,25 +5719,28 @@ static function (): void {
57165719 $ nodeCallback (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scope );
57175720 if ($ propertyReflection !== null && $ propertyReflection ->canChangeTypeAfterAssignment ()) {
57185721 if ($ propertyReflection ->hasNativeType ()) {
5719- $ assignedNativeType = $ scope ->getNativeType ($ assignedExpr );
57205722 $ propertyNativeType = $ propertyReflection ->getNativeType ();
5723+ $ assignedTypeIsCompatible = $ propertyNativeType ->isSuperTypeOf ($ assignedExprType )->yes ();
57215724
5722- $ assignedTypeIsCompatible = false ;
5723- foreach (TypeUtils::flattenTypes ($ propertyNativeType ) as $ type ) {
5724- if ($ type ->isSuperTypeOf ($ assignedNativeType )->yes ()) {
5725- $ assignedTypeIsCompatible = true ;
5726- break ;
5725+ if (!$ assignedTypeIsCompatible ) {
5726+ foreach (TypeUtils::flattenTypes ($ propertyNativeType ) as $ type ) {
5727+ if ($ type ->isSuperTypeOf ($ assignedExprType )->yes ()) {
5728+ $ assignedTypeIsCompatible = true ;
5729+ break ;
5730+ }
57275731 }
57285732 }
57295733
57305734 if ($ assignedTypeIsCompatible ) {
5731- $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ assignedNativeType );
5735+ $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ scope -> getNativeType ( $ assignedExpr ) );
57325736 } elseif ($ scope ->isDeclareStrictTypes ()) {
57335737 $ scope = $ scope ->assignExpression (
57345738 $ var ,
57355739 TypeCombinator::intersect ($ assignedExprType ->toCoercedArgumentType (true ), $ propertyNativeType ),
5736- TypeCombinator::intersect ($ assignedNativeType ->toCoercedArgumentType (true ), $ propertyNativeType ),
5740+ TypeCombinator::intersect ($ scope -> getNativeType ( $ assignedExpr ) ->toCoercedArgumentType (true ), $ propertyNativeType ),
57375741 );
5742+ } else {
5743+ $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ scope ->getNativeType ($ assignedExpr ));
57385744 }
57395745 } else {
57405746 $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ scope ->getNativeType ($ assignedExpr ));
0 commit comments