@@ -5626,9 +5626,20 @@ static function (): void {
5626
5626
$ nodeCallback (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scope );
5627
5627
if ($ propertyReflection ->canChangeTypeAfterAssignment ()) {
5628
5628
if ($ propertyReflection ->hasNativeType () && $ scope ->isDeclareStrictTypes ()) {
5629
+ $ assignedNativeType = $ scope ->getNativeType ($ assignedExpr );
5629
5630
$ propertyNativeType = $ propertyReflection ->getNativeType ();
5630
5631
5631
- $ scope = $ scope ->assignExpression ($ var , TypeCombinator::intersect ($ assignedExprType ->toCoercedArgumentType (true ), $ propertyNativeType ), TypeCombinator::intersect ($ scope ->getNativeType ($ assignedExpr )->toCoercedArgumentType (true ), $ propertyNativeType ));
5632
+ $ newAssignedType = TypeCombinator::intersect ($ assignedExprType , $ propertyNativeType );
5633
+ if ($ newAssignedType instanceof NeverType) {
5634
+ $ newAssignedType = TypeCombinator::intersect ($ assignedExprType ->toCoercedArgumentType (true ), $ propertyNativeType );
5635
+ }
5636
+
5637
+ $ newAssignedNativeType = TypeCombinator::intersect ($ assignedNativeType , $ propertyNativeType );
5638
+ if ($ newAssignedNativeType instanceof NeverType) {
5639
+ $ newAssignedNativeType = TypeCombinator::intersect ($ assignedNativeType ->toCoercedArgumentType (true ), $ propertyNativeType );
5640
+ }
5641
+
5642
+ $ scope = $ scope ->assignExpression ($ var , $ newAssignedType , $ newAssignedNativeType );
5632
5643
} else {
5633
5644
$ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ scope ->getNativeType ($ assignedExpr ));
5634
5645
}
@@ -5697,9 +5708,20 @@ static function (): void {
5697
5708
$ nodeCallback (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scope );
5698
5709
if ($ propertyReflection !== null && $ propertyReflection ->canChangeTypeAfterAssignment ()) {
5699
5710
if ($ propertyReflection ->hasNativeType () && $ scope ->isDeclareStrictTypes ()) {
5711
+ $ assignedNativeType = $ scope ->getNativeType ($ assignedExpr );
5700
5712
$ propertyNativeType = $ propertyReflection ->getNativeType ();
5701
5713
5702
- $ scope = $ scope ->assignExpression ($ var , TypeCombinator::intersect ($ assignedExprType ->toCoercedArgumentType (true ), $ propertyNativeType ), TypeCombinator::intersect ($ scope ->getNativeType ($ assignedExpr )->toCoercedArgumentType (true ), $ propertyNativeType ));
5714
+ $ newAssignedType = TypeCombinator::intersect ($ assignedExprType , $ propertyNativeType );
5715
+ if ($ newAssignedType instanceof NeverType) {
5716
+ $ newAssignedType = TypeCombinator::intersect ($ assignedExprType ->toCoercedArgumentType (true ), $ propertyNativeType );
5717
+ }
5718
+
5719
+ $ newAssignedNativeType = TypeCombinator::intersect ($ assignedNativeType , $ propertyNativeType );
5720
+ if ($ newAssignedNativeType instanceof NeverType) {
5721
+ $ newAssignedNativeType = TypeCombinator::intersect ($ assignedNativeType ->toCoercedArgumentType (true ), $ propertyNativeType );
5722
+ }
5723
+
5724
+ $ scope = $ scope ->assignExpression ($ var , $ newAssignedType , $ newAssignedNativeType );
5703
5725
} else {
5704
5726
$ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ scope ->getNativeType ($ assignedExpr ));
5705
5727
}
0 commit comments