1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

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

This commit is contained in:
Matthew Brown 2019-12-08 21:19:29 -05:00
parent e3d108ebd9
commit d6a731be73
2 changed files with 18 additions and 0 deletions

View File

@ -559,6 +559,10 @@ class CommentAnalyzer
$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 @@ class CommentAnalyzer
$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 @@ class CommentAnalyzer
$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)
) {

View File

@ -1277,6 +1277,12 @@ class FunctionTemplateTest extends TestCase
apply(new Printer(), new B());',
'error_message' => 'InvalidArgument'
],
'invalidTemplateDocblock' => [
'<?php
/** @template */
function f():void {}',
'error_message' => 'MissingDocblockType'
],
];
}
}