@@ -5628,24 +5628,25 @@ 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- } elseif ( $ scope -> isDeclareStrictTypes ()) {
5644+ $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ scope -> getNativeType ( $ assignedExpr ) );
5645+ } else {
56455646 $ scope = $ scope ->assignExpression (
56465647 $ var ,
5647- TypeCombinator::intersect ($ assignedExprType ->toCoercedArgumentType (true ), $ propertyNativeType ),
5648- TypeCombinator::intersect ($ assignedNativeType -> toCoercedArgumentType (true ), $ propertyNativeType ),
5648+ TypeCombinator::intersect ($ assignedExprType ->toCoercedArgumentType ($ scope -> isDeclareStrictTypes () ), $ propertyNativeType ),
5649+ TypeCombinator::intersect ($ scope -> getNativeType ( $ assignedExpr )-> toCoercedArgumentType ($ scope -> isDeclareStrictTypes () ), $ propertyNativeType ),
56495650 );
56505651 }
56515652 } else {
@@ -5716,24 +5717,25 @@ static function (): void {
57165717 $ nodeCallback (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scope );
57175718 if ($ propertyReflection !== null && $ propertyReflection ->canChangeTypeAfterAssignment ()) {
57185719 if ($ propertyReflection ->hasNativeType ()) {
5719- $ assignedNativeType = $ scope ->getNativeType ($ assignedExpr );
57205720 $ propertyNativeType = $ propertyReflection ->getNativeType ();
5721+ $ assignedTypeIsCompatible = $ propertyNativeType ->isSuperTypeOf ($ assignedExprType )->yes ();
57215722
5722- $ assignedTypeIsCompatible = false ;
5723- foreach (TypeUtils::flattenTypes ($ propertyNativeType ) as $ type ) {
5724- if ($ type ->isSuperTypeOf ($ assignedNativeType )->yes ()) {
5725- $ assignedTypeIsCompatible = true ;
5726- break ;
5723+ if (!$ assignedTypeIsCompatible ) {
5724+ foreach (TypeUtils::flattenTypes ($ propertyNativeType ) as $ type ) {
5725+ if ($ type ->isSuperTypeOf ($ assignedExprType )->yes ()) {
5726+ $ assignedTypeIsCompatible = true ;
5727+ break ;
5728+ }
57275729 }
57285730 }
57295731
57305732 if ($ assignedTypeIsCompatible ) {
5731- $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ assignedNativeType );
5732- } elseif ( $ scope -> isDeclareStrictTypes ()) {
5733+ $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ scope -> getNativeType ( $ assignedExpr ) );
5734+ } else {
57335735 $ scope = $ scope ->assignExpression (
57345736 $ var ,
5735- TypeCombinator::intersect ($ assignedExprType ->toCoercedArgumentType (true ), $ propertyNativeType ),
5736- TypeCombinator::intersect ($ assignedNativeType -> toCoercedArgumentType (true ), $ propertyNativeType ),
5737+ TypeCombinator::intersect ($ assignedExprType ->toCoercedArgumentType ($ scope -> isDeclareStrictTypes () ), $ propertyNativeType ),
5738+ TypeCombinator::intersect ($ scope -> getNativeType ( $ assignedExpr )-> toCoercedArgumentType ($ scope -> isDeclareStrictTypes () ), $ propertyNativeType ),
57375739 );
57385740 }
57395741 } else {
0 commit comments