Skip to content
Permalink
Browse files

Fix #2441 - add error when @template type is missing

  • Loading branch information
muglug committed Dec 9, 2019
1 parent e3d108e commit d6a731be73ba7e1f3fa35231e3921c834e2dec9b
Showing with 18 additions and 0 deletions.
  1. +12 −0 src/Psalm/Internal/Analyzer/CommentAnalyzer.php
  2. +6 −0 tests/Template/FunctionTemplateTest.php
@@ -559,6 +559,10 @@ public static function extractFunctionDocblockInfo(PhpParser\Comment\Doc $commen

$template_name = array_shift($template_type);

if (!$template_name) {
throw new IncorrectDocblockException('Empty @template tag');
}

if (count($template_type) > 1
&& in_array(strtolower($template_type[0]), ['as', 'super', 'of'], true)
) {
@@ -731,6 +735,10 @@ public static function extractClassLikeDocblockInfo(

$template_name = array_shift($template_type);

if (!$template_name) {
throw new IncorrectDocblockException('Empty @template tag');
}

if (count($template_type) > 1
&& in_array(strtolower($template_type[0]), ['as', 'super', 'of'], true)
) {
@@ -764,6 +772,10 @@ public static function extractClassLikeDocblockInfo(

$template_name = array_shift($template_type);

if (!$template_name) {
throw new IncorrectDocblockException('Empty @template-covariant tag');
}

if (count($template_type) > 1
&& in_array(strtolower($template_type[0]), ['as', 'super', 'of'], true)
) {
@@ -1277,6 +1277,12 @@ public function __invoke(A $a) : void {
apply(new Printer(), new B());',
'error_message' => 'InvalidArgument'
],
'invalidTemplateDocblock' => [
'<?php
/** @template */
function f():void {}',
'error_message' => 'MissingDocblockType'
],
];
}
}

0 comments on commit d6a731b

Please sign in to comment.
You can’t perform that action at this time.