Skip to content

Commit 2d7400d

Browse files
Rework
1 parent 84396c2 commit 2d7400d

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

src/Analyser/MutatingScope.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,7 +2020,9 @@ public function enterAnonymousFunctionWithoutReflection(
20202020
$paramExprString = sprintf('$%s', $parameter->var->name);
20212021
$isNullable = $this->isParameterValueNullable($parameter);
20222022
$parameterType = $this->getFunctionType($parameter->type, $isNullable, $parameter->variadic);
2023-
$parameterType = self::resolveCallableParameterType($parameterType, $callableParameters, $i);
2023+
if ($callableParameters !== null) {
2024+
$parameterType = self::intersectButNotNever($parameterType, $this->getCallableParameterType($callableParameters, $i));
2025+
}
20242026
$holder = ExpressionTypeHolder::createYes($parameter->var, $parameterType);
20252027
$expressionTypes[$paramExprString] = $holder;
20262028
$nativeTypes[$paramExprString] = $holder;
@@ -2218,7 +2220,9 @@ public function enterArrowFunctionWithoutReflection(Expr\ArrowFunction $arrowFun
22182220
foreach ($arrowFunction->params as $i => $parameter) {
22192221
$isNullable = $this->isParameterValueNullable($parameter);
22202222
$parameterType = $this->getFunctionType($parameter->type, $isNullable, $parameter->variadic);
2221-
$parameterType = self::resolveCallableParameterType($parameterType, $callableParameters, $i);
2223+
if ($callableParameters !== null) {
2224+
$parameterType = self::intersectButNotNever($parameterType, $this->getCallableParameterType($callableParameters, $i));
2225+
}
22222226

22232227
if (!$parameter->var instanceof Variable || !is_string($parameter->var->name)) {
22242228
throw new ShouldNotHappenException();
@@ -2284,26 +2288,24 @@ public function getFunctionType($type, bool $isNullable, bool $isVariadic): Type
22842288
}
22852289

22862290
/**
2287-
* @param ParameterReflection[]|null $callableParameters
2291+
* @param ParameterReflection[] $callableParameters
22882292
*/
2289-
private static function resolveCallableParameterType(Type $declaredType, ?array $callableParameters, int $i): Type
2293+
private function getCallableParameterType(array $callableParameters, int $index): Type
22902294
{
2291-
if ($callableParameters === null) {
2292-
return $declaredType;
2295+
if (isset($callableParameters[$index])) {
2296+
return $callableParameters[$index]->getType();
22932297
}
22942298

2295-
if (isset($callableParameters[$i])) {
2296-
return self::intersectButNotNever($declaredType, $callableParameters[$i]->getType());
2299+
if (count($callableParameters) === 0) {
2300+
return new MixedType();
22972301
}
22982302

2299-
if (count($callableParameters) > 0) {
2300-
$lastParameter = array_last($callableParameters);
2301-
if ($lastParameter->isVariadic()) {
2302-
return self::intersectButNotNever($declaredType, $lastParameter->getType());
2303-
}
2303+
$lastParameter = array_last($callableParameters);
2304+
if ($lastParameter->isVariadic()) {
2305+
return $lastParameter->getType();
23042306
}
23052307

2306-
return self::intersectButNotNever($declaredType, new MixedType());
2308+
return new MixedType();
23072309
}
23082310

23092311
public static function intersectButNotNever(Type $nativeType, Type $inferredType): Type

0 commit comments

Comments
 (0)