@@ -2624,6 +2624,43 @@ static function (): void {
26242624 $ returnType = $ parametersAcceptor ->getReturnType ();
26252625 $ isAlwaysTerminating = $ isAlwaysTerminating || $ returnType instanceof NeverType && $ returnType ->isExplicit ();
26262626 }
2627+
2628+ if (
2629+ $ expr ->name instanceof Name
2630+ && $ functionReflection !== null
2631+ && $ functionReflection ->getName () === 'clone '
2632+ && count ($ expr ->getArgs ()) === 2
2633+ ) {
2634+ $ clonePropertiesArgType = $ scope ->getType ($ expr ->getArgs ()[1 ]->value );
2635+ $ cloneExpr = new TypeExpr ($ scope ->getType (new Expr \Clone_ ($ expr ->getArgs ()[0 ]->value )));
2636+ $ clonePropertiesArgTypeConstantArrays = $ clonePropertiesArgType ->getConstantArrays ();
2637+ foreach ($ clonePropertiesArgTypeConstantArrays as $ clonePropertiesArgTypeConstantArray ) {
2638+ foreach ($ clonePropertiesArgTypeConstantArray ->getKeyTypes () as $ i => $ clonePropertyKeyType ) {
2639+ $ clonePropertyKeyTypeScalars = $ clonePropertyKeyType ->getConstantScalarValues ();
2640+ $ propertyAttributes = $ expr ->getAttributes ();
2641+ $ propertyAttributes ['inCloneWith ' ] = true ;
2642+ if (count ($ clonePropertyKeyTypeScalars ) === 1 ) {
2643+ $ this ->processVirtualAssign (
2644+ $ scope ,
2645+ $ stmt ,
2646+ new PropertyFetch ($ cloneExpr , (string ) $ clonePropertyKeyTypeScalars [0 ], $ propertyAttributes ),
2647+ new TypeExpr ($ clonePropertiesArgTypeConstantArray ->getValueTypes ()[$ i ]),
2648+ $ nodeCallback ,
2649+ );
2650+ continue ;
2651+ }
2652+
2653+ $ this ->processVirtualAssign (
2654+ $ scope ,
2655+ $ stmt ,
2656+ new PropertyFetch ($ cloneExpr , new TypeExpr ($ clonePropertyKeyType ), $ propertyAttributes ),
2657+ new TypeExpr ($ clonePropertiesArgTypeConstantArray ->getValueTypes ()[$ i ]),
2658+ $ nodeCallback ,
2659+ );
2660+ }
2661+ }
2662+ }
2663+
26272664 $ result = $ this ->processArgs ($ stmt , $ functionReflection , null , $ parametersAcceptor , $ expr , $ scope , $ nodeCallback , $ context );
26282665 $ scope = $ result ->getScope ();
26292666 $ hasYield = $ result ->hasYield ();
0 commit comments