-
-
Notifications
You must be signed in to change notification settings - Fork 927
Closed
Labels
Milestone
Description
Bug report
In the given example, there's this piece of code
$value1 = $value->map(function ($value) {
PHPStan\dumpType($value[0]);
PHPStan\dumpType($value[1]);
return $value[0] + $value[1];
});
PHPStan\dumpType($value1);
that is said to return a sum of two integers, but in the generic the type is inferred as a union:
Option<(array|float|int)>
Code snippet that reproduces the problem
https://phpstan.org/r/e53857ea-5194-433e-ade5-725a7126864b
Expected output
If we manually type the return of the closure
$value2 = $value->map(function ($value): int {
PHPStan\dumpType($value[0]);
PHPStan\dumpType($value[1]);
return $value[0] + $value[1];
});
PHPStan\dumpType($value2);
then the correct generic is inferred:
Option<int>
While this is manageable by typing the return type of the closure, maybe having this bug fixed would help to infer more precise types to a whole codebase
Did PHPStan help you today? Did it make you happy in any way?
I absolutely love PHPStan!