From fefd4861d6641e2104972a3d3fc22670b2eed41d Mon Sep 17 00:00:00 2001 From: Teemu Koskinen Date: Sat, 6 Aug 2022 02:27:01 +0300 Subject: [PATCH 1/2] Use $codebase->classlike_storage_provider only if it has the required data. Fixes #8373 --- src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php b/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php index 7d6dbf6ce..c09b16e70 100644 --- a/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php +++ b/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php @@ -1138,7 +1138,7 @@ class TemplateStandinTypeReplacer ): array { if ($input_type_part instanceof TGenericObject || $input_type_part instanceof TIterable) { $input_type_params = $input_type_part->type_params; - } else { + } elseif ($codebase->classlike_storage_provider->has($input_type_part->value)) { $class_storage = $codebase->classlike_storage_provider->get($input_type_part->value); $container_class = $container_type_part->value; @@ -1150,6 +1150,8 @@ class TemplateStandinTypeReplacer } else { $input_type_params = array_fill(0, count($class_storage->template_types ?? []), Type::getMixed()); } + } else { + $input_type_params = []; } try { From 89b7b3234bf8b4fabf154b0594726b6b1c137602 Mon Sep 17 00:00:00 2001 From: Teemu Koskinen Date: Mon, 8 Aug 2022 23:47:11 +0300 Subject: [PATCH 2/2] Add test for #8373 Undefined classes in function dockblocks should not crash psalm. Test provided by @AndrolGenhald --- tests/Template/ClassTemplateTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/Template/ClassTemplateTest.php b/tests/Template/ClassTemplateTest.php index b76c93c3e..ee84dbce8 100644 --- a/tests/Template/ClassTemplateTest.php +++ b/tests/Template/ClassTemplateTest.php @@ -3826,6 +3826,22 @@ class ClassTemplateTest extends TestCase } }', ], + 'undefined class in function dockblock' => [ + ' $baz + */ + function foobar(DoesNotExist $baz): void {} + + /** + * @psalm-suppress UndefinedDocblockClass, UndefinedClass + * @var DoesNotExist + */ + $baz = new DoesNotExist(); + foobar($baz);', + ], ]; }