1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

#8363 - support static as a type parameter in return types of the first-class callables

This commit is contained in:
someniatko 2022-08-04 17:16:06 +03:00
parent f3d67845c5
commit be02e7e5c7
2 changed files with 41 additions and 2 deletions

View File

@ -512,7 +512,18 @@ class AtomicStaticCallAnalyzer
}
}
$statements_analyzer->node_data->setType($stmt, $return_type_candidate);
$expanded_return_type = TypeExpander::expandUnion(
$codebase,
$return_type_candidate,
$context->self,
$class_storage->name,
$context->parent,
true,
false,
true
);
$statements_analyzer->node_data->setType($stmt, $expanded_return_type);
return true;
}

View File

@ -751,7 +751,7 @@ class ClosureTest extends TestCase
[],
'8.1'
],
'FirstClassCallable:OverriddenStaticMethod' => [
'FirstClassCallable:InheritedStaticMethod' => [
'<?php
abstract class A
@ -772,6 +772,34 @@ class ClosureTest extends TestCase
[],
'8.1',
],
'FirstClassCallable:InheritedStaticMethodWithStaticTypeParameter' => [
'<?php
/** @template T */
class Holder
{
/** @param T $value */
public function __construct(public $value) {}
}
abstract class A
{
final public function __construct(public int $i) {}
/** @return Holder<static> */
public static function create(int $i): Holder
{
return new Holder(new static($i));
}
}
class C extends A {}
/** @param \Closure(int):Holder<C> $_ */
function takesIntToHolder(\Closure $_): void {}
takesIntToHolder(C::create(...));'
],
'FirstClassCallable:WithArrayMap' => [
'<?php
$array = [1, 2, 3];