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' => [ '