@@ -1543,7 +1543,7 @@ private function specifyTypesFromConditionalReturnType(
15431543 return null ;
15441544 }
15451545
1546- $ argsMap = [] ;
1546+ $ argumentExpr = null ;
15471547 $ parameters = $ parametersAcceptor ->getParameters ();
15481548 foreach ($ call ->getArgs () as $ i => $ arg ) {
15491549 if ($ arg ->unpack ) {
@@ -1558,28 +1558,28 @@ private function specifyTypesFromConditionalReturnType(
15581558 continue ;
15591559 }
15601560
1561- $ argsMap ['$ ' . $ paramName ] = $ arg ->value ;
1561+ if ($ returnType ->getParameterName () !== '$ ' . $ paramName ) {
1562+ continue ;
1563+ }
1564+
1565+ $ argumentExpr = $ arg ->value ;
1566+ }
1567+
1568+ if ($ argumentExpr === null ) {
1569+ return null ;
15621570 }
15631571
1564- return $ this ->getConditionalSpecifiedTypes ($ returnType , $ leftType , $ rightType , $ scope , $ argsMap );
1572+ return $ this ->getConditionalSpecifiedTypes ($ returnType , $ leftType , $ rightType , $ scope , $ argumentExpr );
15651573 }
15661574
1567- /**
1568- * @param array<string, Expr> $argsMap
1569- */
15701575 private function getConditionalSpecifiedTypes (
15711576 ConditionalTypeForParameter $ conditionalType ,
15721577 Type $ leftType ,
15731578 Type $ rightType ,
15741579 Scope $ scope ,
1575- array $ argsMap ,
1580+ Expr $ argumentExpr ,
15761581 ): ?SpecifiedTypes
15771582 {
1578- $ parameterName = $ conditionalType ->getParameterName ();
1579- if (!array_key_exists ($ parameterName , $ argsMap )) {
1580- return null ;
1581- }
1582-
15831583 $ targetType = $ conditionalType ->getTarget ();
15841584 $ ifType = $ conditionalType ->getIf ();
15851585 $ elseType = $ conditionalType ->getElse ();
@@ -1593,7 +1593,7 @@ private function getConditionalSpecifiedTypes(
15931593 }
15941594
15951595 $ specifiedTypes = $ this ->create (
1596- $ argsMap [ $ parameterName ] ,
1596+ $ argumentExpr ,
15971597 $ targetType ,
15981598 $ context ,
15991599 $ scope ,
@@ -1604,7 +1604,7 @@ private function getConditionalSpecifiedTypes(
16041604 $ context = $ context ->negate ();
16051605 }
16061606
1607- $ specifiedTypes = $ specifiedTypes ->unionWith ($ this ->specifyTypesInCondition ($ scope , $ argsMap [ $ parameterName ] , $ context ));
1607+ $ specifiedTypes = $ specifiedTypes ->unionWith ($ this ->specifyTypesInCondition ($ scope , $ argumentExpr , $ context ));
16081608 }
16091609
16101610 return $ specifiedTypes ;
0 commit comments