1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix #660 - always refer closure types

This commit is contained in:
Matthew Brown 2018-04-09 22:00:36 -04:00
parent 5f47374606
commit 5915718013
2 changed files with 28 additions and 1 deletions

View File

@ -481,7 +481,16 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
$storage->return_type_location
);
if (!$storage->return_type || $storage->return_type->isMixed()) {
if ($this->function->inferredType
&& (!$storage->return_type
|| $storage->return_type->isMixed()
|| TypeChecker::isContainedBy(
$project_checker->codebase,
$this->function->inferredType,
$storage->return_type
)
)
) {
$closure_yield_types = [];
$closure_return_types = EffectsAnalyser::getReturnTypes(
$this->function->stmts,

View File

@ -413,6 +413,24 @@ class CallableTest extends TestCase
'$a' => 'A',
],
],
'inferClosureTypeWithTypehint' => [
'<?php
$adder1 = function(int $i) : callable {
return function(int $j) use ($i) : int {
return $i + $j;
};
};
$adder2 = function(int $i) {
return function(int $j) use ($i) : int {
return $i + $j;
};
};',
'assertions' => [
'$adder1' => 'Closure(int):Closure(int):int',
'$adder2' => 'Closure(int):Closure(int):int',
],
'error_levels' => ['MissingClosureReturnType'],
],
];
}