From ac79e9a3119eb7f35402a8e8ca09a12c51c3c5e3 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Thu, 31 Jan 2019 21:06:21 -0500 Subject: [PATCH] Fix #1263 - return proper class string --- src/Psalm/Type/Union.php | 5 ++++- tests/ClassStringTest.php | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Type/Union.php b/src/Psalm/Type/Union.php index 8dbb13064..0e887334d 100644 --- a/src/Psalm/Type/Union.php +++ b/src/Psalm/Type/Union.php @@ -1059,7 +1059,10 @@ class Union $new_types[$unknown_class_string->getKey()] = $unknown_class_string; } elseif ($template_type_part instanceof Type\Atomic\TNamedObject) { - $literal_class_string = new Type\Atomic\TClassString($template_type_part->value); + $literal_class_string = new Type\Atomic\TClassString( + $template_type_part->value, + $template_type_part + ); $new_types[$literal_class_string->getKey()] = $literal_class_string; } diff --git a/tests/ClassStringTest.php b/tests/ClassStringTest.php index 41c2e15fe..9321b321c 100644 --- a/tests/ClassStringTest.php +++ b/tests/ClassStringTest.php @@ -485,6 +485,18 @@ class ClassStringTest extends TestCase } }' ], + 'returnTemplatedClassString' => [ + ' $shouldBe + * @return class-string + */ + function identity(string $shouldBe) : string { return $shouldBe; } + + identity(DateTimeImmutable::class)::createFromMutable(new DateTime());', + ], ]; }