@@ -5625,12 +5625,15 @@ static function (): void {
5625
5625
$ assignedExprType = $ scope ->getType ($ assignedExpr );
5626
5626
$ nodeCallback (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scope );
5627
5627
if ($ propertyReflection ->canChangeTypeAfterAssignment ()) {
5628
- if ( $ propertyReflection -> hasNativeType () && $ scope ->isDeclareStrictTypes ()) {
5629
- $ propertyNativeType = $ propertyReflection ->getNativeType ();
5628
+ $ assignedNativeType = $ scope ->getNativeType ( $ assignedExpr );
5629
+ $ propertyNativeType = $ propertyReflection ->getNativeType ();
5630
5630
5631
- $ scope = $ scope ->assignExpression ($ var , TypeCombinator::intersect ($ assignedExprType ->toCoercedArgumentType (true ), $ propertyNativeType ), TypeCombinator::intersect ($ scope ->getNativeType ($ assignedExpr )->toCoercedArgumentType (true ), $ propertyNativeType ));
5631
+ if ($ propertyReflection ->hasNativeType () && $ scope ->isDeclareStrictTypes ()) {
5632
+ $ scope = $ scope ->assignExpression ($ var , TypeCombinator::intersect ($ assignedExprType ->toCoercedArgumentType (true ), $ propertyNativeType ), TypeCombinator::intersect ($ assignedNativeType ->toCoercedArgumentType (true ), $ propertyNativeType ));
5633
+ } elseif ($ propertyNativeType ->isNull ()->no ()) {
5634
+ $ scope = $ scope ->assignExpression ($ var , TypeCombinator::removeNull ($ assignedExprType ), TypeCombinator::removeNull ($ assignedNativeType ));
5632
5635
} else {
5633
- $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ scope -> getNativeType ( $ assignedExpr ) );
5636
+ $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ assignedNativeType );
5634
5637
}
5635
5638
}
5636
5639
$ declaringClass = $ propertyReflection ->getDeclaringClass ();
@@ -5696,12 +5699,15 @@ static function (): void {
5696
5699
$ assignedExprType = $ scope ->getType ($ assignedExpr );
5697
5700
$ nodeCallback (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scope );
5698
5701
if ($ propertyReflection !== null && $ propertyReflection ->canChangeTypeAfterAssignment ()) {
5699
- if ( $ propertyReflection -> hasNativeType () && $ scope ->isDeclareStrictTypes ()) {
5700
- $ propertyNativeType = $ propertyReflection ->getNativeType ();
5702
+ $ assignedNativeType = $ scope ->getNativeType ( $ assignedExpr );
5703
+ $ propertyNativeType = $ propertyReflection ->getNativeType ();
5701
5704
5702
- $ scope = $ scope ->assignExpression ($ var , TypeCombinator::intersect ($ assignedExprType ->toCoercedArgumentType (true ), $ propertyNativeType ), TypeCombinator::intersect ($ scope ->getNativeType ($ assignedExpr )->toCoercedArgumentType (true ), $ propertyNativeType ));
5705
+ if ($ propertyReflection ->hasNativeType () && $ scope ->isDeclareStrictTypes ()) {
5706
+ $ scope = $ scope ->assignExpression ($ var , TypeCombinator::intersect ($ assignedExprType ->toCoercedArgumentType (true ), $ propertyNativeType ), TypeCombinator::intersect ($ assignedNativeType ->toCoercedArgumentType (true ), $ propertyNativeType ));
5707
+ } elseif ($ propertyNativeType ->isNull ()->no ()) {
5708
+ $ scope = $ scope ->assignExpression ($ var , TypeCombinator::removeNull ($ assignedExprType ), TypeCombinator::removeNull ($ assignedNativeType ));
5703
5709
} else {
5704
- $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ scope -> getNativeType ( $ assignedExpr ) );
5710
+ $ scope = $ scope ->assignExpression ($ var , $ assignedExprType , $ assignedNativeType );
5705
5711
}
5706
5712
}
5707
5713
} else {
0 commit comments