@@ -58,11 +58,11 @@ public function getTypeFromFunctionCall(
5858 FunctionReflection $ functionReflection ,
5959 FuncCall $ functionCall ,
6060 Scope $ scope ,
61- ): Type
61+ ): ? Type
6262 {
6363 $ type = $ this ->getPreliminarilyResolvedTypeFromFunctionCall ($ functionReflection , $ functionCall , $ scope );
6464
65- if ($ this ->canReturnNull ($ functionReflection , $ functionCall , $ scope )) {
65+ if ($ type !== null && $ this ->canReturnNull ($ functionReflection , $ functionCall , $ scope )) {
6666 $ type = TypeCombinator::addNull ($ type );
6767 }
6868
@@ -73,21 +73,22 @@ private function getPreliminarilyResolvedTypeFromFunctionCall(
7373 FunctionReflection $ functionReflection ,
7474 FuncCall $ functionCall ,
7575 Scope $ scope ,
76- ): Type
76+ ): ? Type
7777 {
7878 $ subjectArgumentType = $ this ->getSubjectType ($ functionReflection , $ functionCall , $ scope );
7979 $ args = $ functionCall ->getArgs ();
80- $ defaultReturnType = ParametersAcceptorSelector::selectFromArgs (
81- $ scope ,
82- $ args ,
83- $ functionReflection ->getVariants (),
84- )->getReturnType ();
8580
8681 if ($ subjectArgumentType === null ) {
87- return $ defaultReturnType ;
82+ return null ;
8883 }
8984
9085 if ($ subjectArgumentType instanceof MixedType) {
86+ $ defaultReturnType = ParametersAcceptorSelector::selectFromArgs (
87+ $ scope ,
88+ $ args ,
89+ $ functionReflection ->getVariants (),
90+ )->getReturnType ();
91+
9192 return TypeUtils::toBenevolentUnion ($ defaultReturnType );
9293 }
9394
@@ -229,18 +230,11 @@ private function canReturnNull(
229230 ) {
230231 return false ;
231232 }
232- }
233233
234- $ possibleTypes = ParametersAcceptorSelector::selectFromArgs (
235- $ scope ,
236- $ args ,
237- $ functionReflection ->getVariants (),
238- )->getReturnType ();
239-
240- // resolve conditional return types
241- $ possibleTypes = TypeUtils::resolveLateResolvableTypes ($ possibleTypes );
234+ return true ;
235+ }
242236
243- return TypeCombinator:: containsNull ( $ possibleTypes ) ;
237+ return false ;
244238 }
245239
246240}
0 commit comments