@@ -5556,15 +5556,10 @@ static function (): void {
5556
5556
$ assignedExprType = $ scope ->getType ($ assignedExpr );
5557
5557
$ nodeCallback (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scope );
5558
5558
if ($ propertyReflection ->canChangeTypeAfterAssignment ()) {
5559
- if ($ propertyReflection ->hasNativeType ()) {
5559
+ if ($ propertyReflection ->hasNativeType () && $ scope -> isDeclareStrictTypes () ) {
5560
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
- }
5561
+
5562
+ $ scope = $ scope ->assignExpression ($ var , TypeCombinator::intersect ($ assignedExprType ->toCoercedArgumentType (true ), $ propertyNativeType ), TypeCombinator::intersect ($ scope ->getNativeType ($ assignedExpr )->toCoercedArgumentType (true ), $ propertyNativeType ));
5568
5563
} else {
5569
5564
$ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ scope ->getNativeType ($ assignedExpr ));
5570
5565
}
@@ -5632,15 +5627,10 @@ static function (): void {
5632
5627
$ assignedExprType = $ scope ->getType ($ assignedExpr );
5633
5628
$ nodeCallback (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scope );
5634
5629
if ($ propertyReflection !== null && $ propertyReflection ->canChangeTypeAfterAssignment ()) {
5635
- if ($ propertyReflection ->hasNativeType ()) {
5630
+ if ($ propertyReflection ->hasNativeType () && $ scope -> isDeclareStrictTypes () ) {
5636
5631
$ 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
- }
5632
+
5633
+ $ scope = $ scope ->assignExpression ($ var , TypeCombinator::intersect ($ assignedExprType ->toCoercedArgumentType (true ), $ propertyNativeType ), TypeCombinator::intersect ($ scope ->getNativeType ($ assignedExpr )->toCoercedArgumentType (true ), $ propertyNativeType ));
5644
5634
} else {
5645
5635
$ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ scope ->getNativeType ($ assignedExpr ));
5646
5636
}
0 commit comments