@@ -4900,6 +4900,68 @@ public function processAlwaysIterableForeachScopeWithoutPollute(self $finalScope
49004900 );
49014901 }
49024902
4903+ public function processAlwaysIterableForScopeWithoutPollute (self $ finalScope , self $ initScope ): self
4904+ {
4905+ $ expressionTypes = $ this ->expressionTypes ;
4906+ $ initScopeExpressionTypes = $ initScope ->expressionTypes ;
4907+ foreach ($ finalScope ->expressionTypes as $ variableExprString => $ variableTypeHolder ) {
4908+ if (!isset ($ expressionTypes [$ variableExprString ])) {
4909+ if (isset ($ initScopeExpressionTypes [$ variableExprString ])) {
4910+ $ expressionTypes [$ variableExprString ] = ExpressionTypeHolder::createMaybe ($ variableTypeHolder ->getExpr (), $ variableTypeHolder ->getType ());
4911+ continue ;
4912+ }
4913+
4914+ $ expressionTypes [$ variableExprString ] = $ variableTypeHolder ;
4915+ continue ;
4916+ }
4917+
4918+ $ expressionTypes [$ variableExprString ] = new ExpressionTypeHolder (
4919+ $ variableTypeHolder ->getExpr (),
4920+ $ variableTypeHolder ->getType (),
4921+ $ variableTypeHolder ->getCertainty ()->and ($ expressionTypes [$ variableExprString ]->getCertainty ()),
4922+ );
4923+ }
4924+
4925+ $ nativeTypes = $ this ->nativeExpressionTypes ;
4926+ $ initScopeNativeExpressionTypes = $ initScope ->nativeExpressionTypes ;
4927+ foreach ($ finalScope ->nativeExpressionTypes as $ variableExprString => $ variableTypeHolder ) {
4928+ if (!isset ($ nativeTypes [$ variableExprString ])) {
4929+ if (isset ($ initScopeNativeExpressionTypes [$ variableExprString ])) {
4930+ $ nativeTypes [$ variableExprString ] = ExpressionTypeHolder::createMaybe ($ variableTypeHolder ->getExpr (), $ variableTypeHolder ->getType ());
4931+ continue ;
4932+ }
4933+
4934+ $ nativeTypes [$ variableExprString ] = $ variableTypeHolder ;
4935+ continue ;
4936+ }
4937+
4938+ $ nativeTypes [$ variableExprString ] = new ExpressionTypeHolder (
4939+ $ variableTypeHolder ->getExpr (),
4940+ $ variableTypeHolder ->getType (),
4941+ $ variableTypeHolder ->getCertainty ()->and ($ nativeTypes [$ variableExprString ]->getCertainty ()),
4942+ );
4943+ }
4944+
4945+ return $ this ->scopeFactory ->create (
4946+ $ this ->context ,
4947+ $ this ->isDeclareStrictTypes (),
4948+ $ this ->getFunction (),
4949+ $ this ->getNamespace (),
4950+ $ expressionTypes ,
4951+ $ nativeTypes ,
4952+ $ this ->conditionalExpressions ,
4953+ $ this ->inClosureBindScopeClasses ,
4954+ $ this ->anonymousFunctionReflection ,
4955+ $ this ->inFirstLevelStatement ,
4956+ [],
4957+ [],
4958+ [],
4959+ $ this ->afterExtractCall ,
4960+ $ this ->parentScope ,
4961+ $ this ->nativeTypesPromoted ,
4962+ );
4963+ }
4964+
49034965 public function generalizeWith (self $ otherScope ): self
49044966 {
49054967 $ variableTypeHolders = $ this ->generalizeVariableTypeHolders (
0 commit comments