From 3243819f1be0632e2afe9b941a10bb0c754f084a Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Mon, 9 Mar 2020 01:29:16 -0400 Subject: [PATCH] Fix #2941 - allow class-string to be fleshed out --- .../Analyzer/Statements/ExpressionAnalyzer.php | 15 +++++++++++++++ tests/ClassStringTest.php | 17 +++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php index 541cce6eb..c11470af3 100644 --- a/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php @@ -1302,6 +1302,21 @@ class ExpressionAnalyzer } } + if ($return_type instanceof Type\Atomic\TClassString + && $return_type->as_type + ) { + self::fleshOutAtomicType( + $codebase, + $return_type->as_type, + $self_class, + $static_class_type, + $parent_class, + $evaluate + ); + + $return_type->as = $return_type->as_type->value; + } + if ($return_type instanceof Type\Atomic\TScalarClassConstant) { if ($return_type->fq_classlike_name === 'self' && $self_class) { $return_type->fq_classlike_name = $self_class; diff --git a/tests/ClassStringTest.php b/tests/ClassStringTest.php index 0d4287702..754079117 100644 --- a/tests/ClassStringTest.php +++ b/tests/ClassStringTest.php @@ -678,6 +678,23 @@ class ClassStringTest extends TestCase } }', ], + 'selfResolvedOnStaticProperty' => [ + ' */ + private static $c; + + /** + * @return class-string + */ + public static function r() : string + { + return self::$c; + } + }' + ], ]; }