From be02e7e5c714fab38ccc71ef7a09a0beaff60575 Mon Sep 17 00:00:00 2001 From: someniatko Date: Thu, 4 Aug 2022 17:16:06 +0300 Subject: [PATCH] #8363 - support `static` as a type parameter in return types of the first-class callables --- .../StaticMethod/AtomicStaticCallAnalyzer.php | 13 +++++++- tests/ClosureTest.php | 30 ++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticMethod/AtomicStaticCallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticMethod/AtomicStaticCallAnalyzer.php index a147c4aa37a..a4c33c24c08 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticMethod/AtomicStaticCallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticMethod/AtomicStaticCallAnalyzer.php @@ -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; } diff --git a/tests/ClosureTest.php b/tests/ClosureTest.php index e6e5699600e..53e5cc3f9b2 100644 --- a/tests/ClosureTest.php +++ b/tests/ClosureTest.php @@ -751,7 +751,7 @@ public static function __callStatic(string $name, array $args): mixed { [], '8.1' ], - 'FirstClassCallable:OverriddenStaticMethod' => [ + 'FirstClassCallable:InheritedStaticMethod' => [ ' [ + ' */ + public static function create(int $i): Holder + { + return new Holder(new static($i)); + } + } + + class C extends A {} + + /** @param \Closure(int):Holder $_ */ + function takesIntToHolder(\Closure $_): void {} + + takesIntToHolder(C::create(...));' + ], 'FirstClassCallable:WithArrayMap' => [ '