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:
parent
5f47374606
commit
5915718013
@ -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,
|
||||
|
@ -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'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user