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

Be more strict about what can be a template as type

This commit is contained in:
Matthew Brown 2019-02-05 17:26:28 -05:00
parent 652b6eb8f2
commit 899dd16e8f
2 changed files with 21 additions and 0 deletions

View File

@ -870,6 +870,19 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
continue;
}
if (!$template_type->isSingle()) {
if (IssueBuffer::accepts(
new InvalidDocblock(
'Template type cannot be a union in docblock for '
. implode('.', $this->fq_classlike_names),
new CodeLocation($this->file_scanner, $node, null, true)
)
)) {
$storage->has_docblock_issues = true;
continue;
}
}
$storage->template_types[$template_name] = [
$template_type,
$fq_classlike_name

View File

@ -2018,6 +2018,14 @@ class TemplateTest extends TestCase
$templated_list->add(5, []);',
'error_message' => 'InvalidArgument',
],
'unionTemplateType' => [
'<?php
/**
* @template T0 as int|string
*/
class Foo {}',
'error_message' => 'InvalidDocblock'
],
];
}
}