Skip to content

Commit

Permalink
vimeo#8363 - support static as a type parameter in return types of …
Browse files Browse the repository at this point in the history
…the first-class callables
  • Loading branch information
someniatko committed Aug 4, 2022
1 parent f3d6784 commit be02e7e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
Expand Up @@ -512,7 +512,18 @@ private static function handleNamedCall(
}
}

$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;
}
Expand Down
30 changes: 29 additions & 1 deletion tests/ClosureTest.php
Expand Up @@ -751,7 +751,7 @@ public static function __callStatic(string $name, array $args): mixed {
[],
'8.1'
],
'FirstClassCallable:OverriddenStaticMethod' => [
'FirstClassCallable:InheritedStaticMethod' => [
'<?php
abstract class A
Expand All @@ -772,6 +772,34 @@ function takesIntToString(\Closure $_): void {}
[],
'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];
Expand Down

0 comments on commit be02e7e

Please sign in to comment.