@@ -5628,24 +5628,25 @@ static function (): void {
5628
5628
$ nodeCallback (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scope );
5629
5629
if ($ propertyReflection ->canChangeTypeAfterAssignment ()) {
5630
5630
if ($ propertyReflection ->hasNativeType ()) {
5631
- $ assignedNativeType = $ scope ->getNativeType ($ assignedExpr );
5632
5631
$ propertyNativeType = $ propertyReflection ->getNativeType ();
5633
5632
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
+ }
5639
5640
}
5640
5641
}
5641
5642
5642
5643
if ($ assignedTypeIsCompatible ) {
5643
- $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ assignedNativeType );
5644
- } elseif ( $ scope -> isDeclareStrictTypes ()) {
5644
+ $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ scope -> getNativeType ( $ assignedExpr ) );
5645
+ } else {
5645
5646
$ scope = $ scope ->assignExpression (
5646
5647
$ 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 ),
5649
5650
);
5650
5651
}
5651
5652
} else {
@@ -5716,24 +5717,25 @@ static function (): void {
5716
5717
$ nodeCallback (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scope );
5717
5718
if ($ propertyReflection !== null && $ propertyReflection ->canChangeTypeAfterAssignment ()) {
5718
5719
if ($ propertyReflection ->hasNativeType ()) {
5719
- $ assignedNativeType = $ scope ->getNativeType ($ assignedExpr );
5720
5720
$ propertyNativeType = $ propertyReflection ->getNativeType ();
5721
+ $ assignedTypeIsCompatible = $ propertyNativeType ->isSuperTypeOf ($ assignedExprType )->yes ();
5721
5722
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
+ }
5727
5729
}
5728
5730
}
5729
5731
5730
5732
if ($ assignedTypeIsCompatible ) {
5731
- $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ assignedNativeType );
5732
- } elseif ( $ scope -> isDeclareStrictTypes ()) {
5733
+ $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ scope -> getNativeType ( $ assignedExpr ) );
5734
+ } else {
5733
5735
$ scope = $ scope ->assignExpression (
5734
5736
$ 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 ),
5737
5739
);
5738
5740
}
5739
5741
} else {
0 commit comments