@@ -5556,15 +5556,10 @@ static function (): void {
55565556 $ assignedExprType = $ scope ->getType ($ assignedExpr );
55575557 $ nodeCallback (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scope );
55585558 if ($ propertyReflection ->canChangeTypeAfterAssignment ()) {
5559- if ($ propertyReflection ->hasNativeType ()) {
5559+ if ($ propertyReflection ->hasNativeType () && $ scope -> isDeclareStrictTypes () ) {
55605560 $ 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 ));
55685563 } else {
55695564 $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ scope ->getNativeType ($ assignedExpr ));
55705565 }
@@ -5632,15 +5627,10 @@ static function (): void {
56325627 $ assignedExprType = $ scope ->getType ($ assignedExpr );
56335628 $ nodeCallback (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scope );
56345629 if ($ propertyReflection !== null && $ propertyReflection ->canChangeTypeAfterAssignment ()) {
5635- if ($ propertyReflection ->hasNativeType ()) {
5630+ if ($ propertyReflection ->hasNativeType () && $ scope -> isDeclareStrictTypes () ) {
56365631 $ 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 ));
56445634 } else {
56455635 $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ scope ->getNativeType ($ assignedExpr ));
56465636 }
0 commit comments