mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Fix #5140 - always replace closure return types, whether or not a matching input type is present
This commit is contained in:
parent
25659dd1a9
commit
0eed186edf
@ -222,16 +222,15 @@ trait CallableTrait
|
||||
}
|
||||
}
|
||||
|
||||
if (($input_type instanceof Atomic\TCallable || $input_type instanceof Atomic\TClosure)
|
||||
&& $callable->return_type
|
||||
&& $input_type->return_type
|
||||
) {
|
||||
if ($callable->return_type) {
|
||||
$callable->return_type = TemplateStandinTypeReplacer::replace(
|
||||
$callable->return_type,
|
||||
$template_result,
|
||||
$codebase,
|
||||
$statements_analyzer,
|
||||
$input_type->return_type,
|
||||
$input_type instanceof Atomic\TCallable || $input_type instanceof Atomic\TClosure
|
||||
? $input_type->return_type
|
||||
: null,
|
||||
$input_arg_offset,
|
||||
$calling_class,
|
||||
$calling_function,
|
||||
|
@ -4282,29 +4282,6 @@ class ClassTemplateExtendsTest extends TestCase
|
||||
function getIterator(): Traversable;
|
||||
}'
|
||||
],
|
||||
'extendsWithoutAlias' => [
|
||||
'<?php
|
||||
/**
|
||||
* @template TAValue
|
||||
*/
|
||||
abstract class A {
|
||||
/**
|
||||
* @psalm-param TAValue $val
|
||||
*/
|
||||
abstract public function foo($val): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* @template TBValue
|
||||
* @extends A<TBValue>
|
||||
*/
|
||||
abstract class B extends A {
|
||||
/**
|
||||
* @psalm-param TBValue $val
|
||||
*/
|
||||
abstract public function foo($val): void;
|
||||
}'
|
||||
],
|
||||
'extendsWithAlias' => [
|
||||
'<?php
|
||||
/**
|
||||
@ -4332,6 +4309,44 @@ class ClassTemplateExtendsTest extends TestCase
|
||||
abstract public function foo($val): void;
|
||||
}'
|
||||
],
|
||||
'extendsWithTemplatedClosureProperty' => [
|
||||
'<?php
|
||||
/**
|
||||
* @template T1
|
||||
*/
|
||||
class A
|
||||
{
|
||||
/**
|
||||
* @var T1|null
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* @var (Closure(): T1)|null
|
||||
*/
|
||||
protected $closure;
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T2
|
||||
* @extends A<T2>
|
||||
*/
|
||||
class B extends A {
|
||||
/**
|
||||
* @return T2|null
|
||||
*/
|
||||
public function getType() {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return (Closure(): T2)|null
|
||||
*/
|
||||
public function getClosureReturningType() {
|
||||
return $this->closure;
|
||||
}
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user